diff --git a/README.md b/README.md index c31e5fe..45d2d23 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,79 @@ -# How to search and select the record in wpf and uwp treegrid? -This example illustrates how to search and select the record in wpf and uwp treegrid +# How to Search and Select the Record in WPF and UWP TreeGrid? + +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). + +## For WPF: + +You can search and select a record in TreeGrid based on the searched text using the TextChanged event of TextBox. + +``` csharp +private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) +{ + var textBox = sender as TextBox; + var treeGrid = this.AssociatedObject.treeGrid; + if (textBox.Text == "") + treeGrid.SelectedItems.Clear(); + + for (int i = 0; i < treeGrid.View.Nodes.Count; i++) + { + if (Provider == null) + Provider = treeGrid.View.GetPropertyAccessProvider(); + + if (treeGrid.View.Nodes[i].HasChildNodes && treeGrid.View.Nodes[i].ChildNodes.Count == 0) + { + treeGrid.BeginInit(); + treeGrid.ExpandNode(treeGrid.View.Nodes[i]); + treeGrid.CollapseNode(treeGrid.View.Nodes[i]); + treeGrid.EndInit(); + } + else if (treeGrid.View.Nodes[i].HasChildNodes) + { + dataRow = (treeGrid.View.Nodes[i].Item as EmployeeInfo); + FindMatchText(dataRow); + GetChildNodes(treeGrid.View.Nodes[i]); + } + else + { + dataRow=(treeGrid.View.Nodes[i].Item as EmployeeInfo); + FindMatchText(dataRow); + } + } +} +``` + +## For UWP: + +You can search and select a record in TreeGrid based on the searched text using the TextChanged event of TextBox. + +``` csharp +private void Textbox_TextChanged(object sender, TextChangedEventArgs e) +{ + var textBox = sender as TextBox; + + if (textBox.Text == "") + treeGrid.SelectedItems.Clear(); + + for (int i = 0; i < treeGrid.View.Nodes.Count; i++) + { + if (Provider == null) + Provider = treeGrid.View.GetPropertyAccessProvider(); + + if (treeGrid.View.Nodes[i].HasChildNodes && treeGrid.View.Nodes[i].ChildNodes.Count == 0) + { + treeGrid.ExpandNode(treeGrid.View.Nodes[i]); + treeGrid.CollapseNode(treeGrid.View.Nodes[i]); + } + else if (treeGrid.View.Nodes[i].HasChildNodes) + { + dataRow = (treeGrid.View.Nodes[i].Item as PersonInfo); + FindMatchText(dataRow); + GetChildNodes(treeGrid.View.Nodes[i]); + } + else + { + dataRow = (treeGrid.View.Nodes[i].Item as PersonInfo); + FindMatchText(dataRow); + } + } +} +``` \ No newline at end of file