|
2 | 2 |
|
3 | 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 | 4 |
|
5 | | -You can search and select a record in `TreeGrid` based on the searched text using the `TextChanged` event of `TextBox`. |
| 5 | +## For WPF: |
6 | 6 |
|
7 | | -``` c# |
| 7 | +You can search and select a record in TreeGrid based on the searched text using the TextChanged event of TextBox. |
| 8 | + |
| 9 | +``` csharp |
8 | 10 | private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) |
9 | 11 | { |
10 | 12 | var textBox = sender as TextBox; |
@@ -38,3 +40,40 @@ private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChan |
38 | 40 | } |
39 | 41 | } |
40 | 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