Hi,
I have bound 2 hierarchic tables with high volume data (approx. 5000 rows in first table and 25000 rows in second table) within the xamdatagrid. I want to select one row in the second table programmatically. If the row is found by ID and I want to set the row active and I want to expand the parent data record. The code takes a lot of time only for the first time.
Also using Records.ExpandAll takes really a lot of time.
Do you have any idea how to enhance the performance?
Thanks a lot and best regards Jan
private static bool SelectRecord(XamDataPresenter datagrid, IEnumerable<Record> records, int index, string viewlevel)
{
bool result = false;
try
foreach (var record in records ?? Enumerable.Empty<Record>())
if (record.ViewableChildRecords != null && record.ViewableChildRecords.Count > 0)
if (SelectRecord(datagrid, record.ViewableChildRecords, index, viewlevel) == true)
break;
if (viewlevel == (string)record.FieldLayout.Key)
DataRecord datarecord = (record as DataRecord);
if (datarecord != null)
var dataitem = datarecord.DataItem;
if (dataitem != null)
int id = (int)datarecord.Cells["ID"].Value;
if (id == index)
if (record.Visibility == Visibility.Visible)
datagrid.ActiveRecord = record;
if (datagrid.ActiveRecord.ParentDataRecord != null)
datagrid.ActiveRecord.ParentDataRecord.IsExpanded = true;
datagrid.BringRecordIntoView(datagrid.ActiveRecord);
result = true;
}
catch (Exception ex)
System.Diagnostics.Debug.WriteLine(ex.ToString());
return result;
Hi Jan,
Is your data filtered or sorted when you are performing the search? If your data is not sorted or filtered, the records present in the grid are shown in the same order as the underlying data so it is possible that you can perform the search on your data directly and then use the index of that data item in the table as the index for the Records collection in order to get the DataRecord. This would be a lot faster than iterating over the Records collection and causing DataRecords to be created as you access them. (The XamDataGrid has weak references to the DataRecords and when they are accessed it creates the full DataRecord object)
Another option might be to try using the XamDataGrid.GetRecordFromDataItem() method. This method also iterates over the records to find the one you are looking for but it may do it slightly better. I'm not sure how much can actually be improved though since you are still trying to iterate over a large amount of data.
Hi Rob thanks for your fast response.
In general the data can be filtered or sorted. From my point of view the main problem is, that the expansion of records using only the method Records.ExpandAll takes really a very long time for the first execution. If all records expanded, the search is fast.
I need a hint how i can improve the performance to expand all nodes.
Best Regards Jan
Are you using DataTables? One of our devs brought up the point that DataTables are actually notoriously slow when trying to iterate over DataRows and obtaining the children. The reason for this is because it has to essentially build the list of children by traversing the entire table that contains all of the children and it has to do this for all of the islands. So if you are using DataTables, I'd actually recommend switching over to a List<T> or ObservableCollection<T>. It'll be much faster to iterate over these types than through a DataTable.
Hi Rob
thanks a lot for your explanation. Yes I using DataTables and bound this to the Grid, because I have a dynamical application and the content of the XamDataGrid is not fixed. In my uses case I have to create the class dynamically so that I can use List<T>.
Thanks a lot again. Regards Jan
You're welcome. While it will definitely involve a bit more work to create the classes dynamically, it will result in a much faster ExpandAll behavior. I built a test application with 5000 parent records and 5 children records for each parent resulting in 25000 child records and ExpandAll completed in a second or two. When I tried it with a DataTable, it took a very long time.
Let me know if you have any further questions on this matter.