Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 79 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
```