This is a migrated thread and some comments may be shown as answers.

Search for specific item

1 Answer 56 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
UTA
Top achievements
Rank 1
UTA asked on 09 Aug 2010, 09:58 PM
Hello,  I am trying to write code that will take a value from a textbox and search for a matching item in my RadTreeView that I have bound to an ObservableCollection that I get from Entity Framework.  My XAML looks like this:

 

 

 

<telerik:HierarchicalDataTemplate x:Key="DivisionVehicleItem">

 

 

 

 

<TextBlock Text="{Binding VehicleNumber}"></TextBlock>

 

 

 

 

</telerik:HierarchicalDataTemplate>

 

 

 

 

 

<telerik:HierarchicalDataTemplate x:Key="DivisionVehicle"

 

 

 

ItemsSource="{Binding AVLVehicles}"

 

 

 

ItemTemplate="{StaticResource DivisionVehicleItem}">

 

 

 

 

<TextBlock Text="{Binding divisionname}"></TextBlock>

 

 

 

 

 

</telerik:HierarchicalDataTemplate>

 

 

 

 

<nav:RadTreeView x:Name="VehicleTreeView"

 

 

 

SelectionMode="Multiple"

 

 

 

ItemsSource="{Binding Path=Divisions, Source={StaticResource TrapezeViewModel}}"

 

 

 

ItemTemplate="{StaticResource DivisionVehicle}"

 

 

 

IsLineEnabled="True"

 

 

 

ItemsOptionListType="CheckList"

 

 

 

IsOptionElementsEnabled="True" />

 



And the search code looks like this:

 

 

 

 

 

 

private void VehicleQuickSearchTextbox_TextChanged(object sender, TextChangedEventArgs e)

 

{

 

 

string path = string.Empty;

 

 

 

foreach (Division division in VehicleTreeView.ItemsSource)

 

{

 

 

foreach (var vehicle in division.AVLVehicles)

 

{

 

 

if (vehicle.VehicleNumber.StartsWith(VehicleQuickSearchTextbox.Text))

 

{

path =

 

string.Format("{0}\\{1}", division.divisionname, vehicle.VehicleNumber);

 

 

 

RadTreeViewItem targetItem = VehicleTreeView.GetItemByPath(path);

 

 

 

if (targetItem != null)

 

{

targetItem.IsSelected =

 

true;

 

}

 

 

break;

 

}

}

 

 

if (path.Length > 0)

 

{

 

 

break;

 

}

}

}

The problem that I am running into is that, no matter what the path is, I always get null for the GetItemByPath call.  Can you tell me what I am doing wrong?

 

 

 

 

 

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 12 Aug 2010, 04:53 PM
Hello David Findlay,

You should set the attached property TextSearch.TextPath of the RadTreeView to the field you want to search by.

<telerik:RadTreeView Name="SampleTreeView"
    ...
    telerik:TextSearch.TextPath="Name"/>

The TextPath property tells which property should be used for the search by GetItemByPath.

I'm attaching a working sample demonstrating the above.

Greetings,
Hristo Milyakov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
UTA
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or