I am using a treegrid that has hierarchy. I want to hide some rows based on the value in the dataItem of the record.
My idea is to iterate through every record, look at the value in the dataitem of the record and set the record.Visibility = Collapsed.
But my grid.Records attribute only gives me the top level records. How can I access the child records of the given record in the grid.
Hello Viswanath Chennuru,
XamTreeGrid has GetRecordFromDataItem method that gets the DataRecord associated with a specific item in the DataSource.
I have created a sample with a XamTreeGrid and two buttons for hiding and displaying the second child record of the second parent record.
That's a snippet code for hiding the record
(this.treeGrid.GetRecordFromDataItem(this.fileNodes[this.parentRecordIndex] .SubNodes[this.childRecordIndex], true) as DataRecord) .Visibility = System.Windows.Visibility.Collapsed;
Please take a look at the sample and let me know if that works for you or if you have any other questions on this matter.
I am wondering how this will impact my grids performance. I have thousands of records in my grid and if I call the GetRecordFromDataItem for each dataItem, will it go through all the records in the grid each time I make the call or does it has some kind of lookup using which it will return the records for the dataItem?
Hello Viswanath,
The performance might get affected by using the GetRecordFromDataItem when we have thousands of records. As you have mentioned, the method will go over the records every time it's called.
What you could consider that is related to the XamTreeGrid is:
- Handle the XamTreeGrid's InitializeRecord event that is fired for every record and you can collapse the record there according to your logic
That's a snippet code showing how to get the DataItem and set record's Visibility:
private void treeGrid_InitializeRecord(object sender, InitializeRecordEventArgs e){ FileNode fileNode = (e.Record as DataRecord).DataItem as FileNode;
// Add your logic for collapsing the DataReocrd e.Record.Visibility = System.Windows.Visibility.Collapsed;}
- Filter your data source items first based on your logic and after that bind them to the XamDataGrid's DataSource
That's a snippet code for binding the XamTreeGrid's DataSource property.
this.treeGrid.DataSource = null;this.treeGrid.DataSource = this.fileNodes;
Please let me know if you have any other questions on this matter.