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
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,
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...