I have a grid with some 800 records, and each record having a "sub-record" containing 1- ~30 items.
Now if I create a button handler doing nothing else but looping through xamDataGrid1.Records and setting IsExpanded=true for each record I wait for nearly a minute with one processor core maxed out.
This is not really usable performance, am I doing something wrong?
Using version 9.1.20091.2023
Ok I tried your second suggestion with rebinding the grid and setting IsExpanded appropriately in InitializeRecord.
By itself that seems to work, but if I add the needed sort workaround to InitializeRecord also then for some data, the grid full of emptyness!?!, but for other data it seems to work.
This shouldn't be this hard!!!
private void xamDataGrid1_InitializeRecord(object sender, InitializeRecordEventArgs e) { // need to sort by timestamp here due to infragistics bug ... xamDataGrid1.FieldLayouts[0].SortedFields.Add(new FieldSortDescription("Timestamp", ListSortDirection.Descending, false)); e.Record.IsExpanded = m_isExpanded; }
private void ExpandCollapse_Executed(object sender, ExecutedRoutedEventArgs e) { m_isExpanded = !m_isExpanded;
// rebind var temp = xamDataGrid1.DataSource; xamDataGrid1.DataSource = null; xamDataGrid1.DataSource = temp; }
So why then is my sample code still excessively slow.. in the order of 10 seconds?
From profiler output I can see the following, which seems to have a way too high percentage
In my InitializeRecordd event handler I have
xamDataGrid1.FieldLayouts[0].SortedFields.Add(new FieldSortDescription("Timestamp", ListSortDirection.Descending, false));
as per Case Number: CAS-22474-ERQFUC
EDIT: what's up with this forum editor.. preview shows post fine, but real post munges it in various ways including censoring arbitrarily from time to times..
I have proposed this two ways to expand the records. XamDataGrid uses virtualizing techniques so that the records out of view are not even created. Expanding only the viewable records will be enough to make the user think that all of them are expanded.
The slow effect is due to the increasing elements in the element tree ( one records contains multiple nested elements ) and more or less the performance is dependant on PC's hardware parameters.
Alex.
actually, I don't need to expand all at once, I just want user to get impression that all records are expanded. I tried your RecordsInViewChanged suggestion, only to find that it also seemed way too slow.
private bool m_isExpanded; private bool m_isExpanding; private void ExpandCollapse_Executed(object sender, ExecutedRoutedEventArgs e) { m_isExpanded = !m_isExpanded; ToggleRecordsInView(); } private void ToggleRecordsInView() { if (m_isExpanding) return; m_isExpanding = true; Record[] viewable = xamDataGrid1.GetRecordsInView(false); foreach (var r in viewable) { r.IsExpanded = m_isExpanded; } m_isExpanding = false; } private void xamDataGrid1_RecordsInViewChanged(object sender, RecordsInViewChangedEventArgs e) { ToggleRecordsInView(); }
Rebinding the grid sounds like an ugly hack...
Hello,
This is true to some extent. On my laptop the whole process is completed in less than 10 seconds, but that is also not satisfactory. It really depends on the hardware. But why do you need to expand all the 800 records, while you can see (for example) 10 at the most?
It is only enough to expand the ones that are currently in view and then expand those who come into view.
You can do this in couple of ways - either RecordsInViewChanged event or InitializeRecord event.
For example, you can use the InitializeRecord event and handle it like this:
void xamDataGrid1_InitializeRecord(object sender, Infragistics.Windows.DataPresenter.Events.InitializeRecordEventArgs {if (shouldExpand){ e.Record.IsExpanded = true;}}
and your button handler only sets this shouldExpand property to true:
private void button1_Click(object sender, RoutedEventArgs e)
{
shouldExpand = true;
xamDataGrid1.DataSource = null;
xamDataGrid1.DataSource = s;
}
Rebinding the grid would be much more faster than expanding all the records.
Regards,