|
1 | | -# How to search and select the record in wpf and uwp treegrid? |
2 | | -This example illustrates how to search and select the record in wpf and uwp treegrid |
| 1 | +# How to Search and Select the Record in WPF and UWP TreeGrid? |
| 2 | + |
| 3 | +This example illustrates how to search and select the record in [WPF TreeGrid](https://www.syncfusion.com/wpf-controls/treegrid) and [UWP TreeGrid](https://www.syncfusion.com/uwp-ui-controls/treegrid) (SfTreeGrid). |
| 4 | + |
| 5 | +## For WPF: |
| 6 | + |
| 7 | +You can search and select a record in TreeGrid based on the searched text using the TextChanged event of TextBox. |
| 8 | + |
| 9 | +``` csharp |
| 10 | +private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) |
| 11 | +{ |
| 12 | + var textBox = sender as TextBox; |
| 13 | + var treeGrid = this.AssociatedObject.treeGrid; |
| 14 | + if (textBox.Text == "") |
| 15 | + treeGrid.SelectedItems.Clear(); |
| 16 | + |
| 17 | + for (int i = 0; i < treeGrid.View.Nodes.Count; i++) |
| 18 | + { |
| 19 | + if (Provider == null) |
| 20 | + Provider = treeGrid.View.GetPropertyAccessProvider(); |
| 21 | + |
| 22 | + if (treeGrid.View.Nodes[i].HasChildNodes && treeGrid.View.Nodes[i].ChildNodes.Count == 0) |
| 23 | + { |
| 24 | + treeGrid.BeginInit(); |
| 25 | + treeGrid.ExpandNode(treeGrid.View.Nodes[i]); |
| 26 | + treeGrid.CollapseNode(treeGrid.View.Nodes[i]); |
| 27 | + treeGrid.EndInit(); |
| 28 | + } |
| 29 | + else if (treeGrid.View.Nodes[i].HasChildNodes) |
| 30 | + { |
| 31 | + dataRow = (treeGrid.View.Nodes[i].Item as EmployeeInfo); |
| 32 | + FindMatchText(dataRow); |
| 33 | + GetChildNodes(treeGrid.View.Nodes[i]); |
| 34 | + } |
| 35 | + else |
| 36 | + { |
| 37 | + dataRow=(treeGrid.View.Nodes[i].Item as EmployeeInfo); |
| 38 | + FindMatchText(dataRow); |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +## For UWP: |
| 45 | + |
| 46 | +You can search and select a record in TreeGrid based on the searched text using the TextChanged event of TextBox. |
| 47 | + |
| 48 | +``` csharp |
| 49 | +private void Textbox_TextChanged(object sender, TextChangedEventArgs e) |
| 50 | +{ |
| 51 | + var textBox = sender as TextBox; |
| 52 | + |
| 53 | + if (textBox.Text == "") |
| 54 | + treeGrid.SelectedItems.Clear(); |
| 55 | + |
| 56 | + for (int i = 0; i < treeGrid.View.Nodes.Count; i++) |
| 57 | + { |
| 58 | + if (Provider == null) |
| 59 | + Provider = treeGrid.View.GetPropertyAccessProvider(); |
| 60 | + |
| 61 | + if (treeGrid.View.Nodes[i].HasChildNodes && treeGrid.View.Nodes[i].ChildNodes.Count == 0) |
| 62 | + { |
| 63 | + treeGrid.ExpandNode(treeGrid.View.Nodes[i]); |
| 64 | + treeGrid.CollapseNode(treeGrid.View.Nodes[i]); |
| 65 | + } |
| 66 | + else if (treeGrid.View.Nodes[i].HasChildNodes) |
| 67 | + { |
| 68 | + dataRow = (treeGrid.View.Nodes[i].Item as PersonInfo); |
| 69 | + FindMatchText(dataRow); |
| 70 | + GetChildNodes(treeGrid.View.Nodes[i]); |
| 71 | + } |
| 72 | + else |
| 73 | + { |
| 74 | + dataRow = (treeGrid.View.Nodes[i].Item as PersonInfo); |
| 75 | + FindMatchText(dataRow); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | +``` |
0 commit comments