this.treeGrid.Loaded += treeGrid_Loaded; void treeGrid_Loaded(object sender, RoutedEventArgs e) { this.treeGrid.InternalGrid.SelectionChanged += InternalGrid_SelectionChanged; }
void InternalGrid_SelectionChanged(object sender, GridSelectionChangedEventArgs e) { //getting the selected node var viewModel = this.treeGrid.DataContext as ViewModel; viewModel.GridTreeNode = (this.treeGrid.SelectedNode as GridTreeNode).Item; var parentItem = (this.treeGrid.SelectedNode as GridTreeNode).ParentItem; |
var viewModel = this.treeGrid.DataContext as ViewModel; if (treeGrid.SelectedNodes.Count == 0) { viewModel.PersonDetails.Add(new PersonInfo() { LastName = "Sunil", FirstName = "Pradap", MyEyeColor = "Gray", DOB = new DateTime() }); treeGrid.InternalGrid.SelectedNodes.Clear(); treeGrid.InternalGrid.SelectedNodes.Add(this.treeGrid.InternalGrid.Nodes[treeGrid.InternalGrid.Nodes.Count - 1]); this.treeGrid.InternalGrid.Nodes[treeGrid.InternalGrid.Nodes.Count - 1].IsSelected = true; } else { var parentNodeItem = (treeGrid.SelectedNode as GridTreeNode).Item as PersonInfo; var parentNode = treeGrid.SelectedNodes[0]; int parentIndex = this.treeGrid.InternalGrid.Nodes.IndexOf(parentNode);
if (parentNodeItem.Children==null) { parentNodeItem.Children = new ObservableCollection<PersonInfo>(); } parentNodeItem.Children.Add((new PersonInfo() { LastName = "Sunil", FirstName = "Pradap", MyEyeColor = "Gray", DOB = new DateTime() })); treeGrid.InternalGrid.SelectedNodes.Clear(); this.treeGrid.InternalGrid.CurrentCell.Deactivate(); this.treeGrid.InternalGrid.Model.Selections.Clear(); treeGrid.InternalGrid.SelectedNodes.Add(this.treeGrid.InternalGrid.Nodes[parentIndex + parentNode.ChildNodes.Count]); this.treeGrid.InternalGrid.Nodes[parentIndex + parentNode.ChildNodes.Count].IsSelected = true;
|
treeGrid.InternalGrid.SelectedNodes.Clear(); treeGrid.InternalGrid.SelectedNodes.Add(this.treeGrid.InternalGrid.Nodes[parentIndex + parentNode.ChildNodes.Count]); |