Hi,
How can I Expand/Collapse All.
I use the following code. But it throws the exception
What am I doing wrong?
private void ExpandAll(Collection<PivotHeaderCell> pivotHeaderCells) { foreach (PivotHeaderCell cell in pivotHeaderCells) { cell.IsExpanded = true; if (cell.Children.Count > 0) CollapseAll(cell.Children); } }
Thanks
Sangeetha
Thank You for your reply Stefan. My code is exactly like yours, so couldn't figure out what was wrong until now. All I had to do was wrap the code in DrillIn in a Dispatcher delegate and it all worked like charm.
Hello Sangeetha,
Thank you for your post. I have been looking through it and I created a sample project for you with the functionality you want. Basically used the code from the Feature Browser and add a comment in the Click event of the Expand button where you should make some changes depending on your data. Please let me know if this helps you or you need further assistance.
Looking Forward for your reply.
Hi Petar,
Thanks for your reply. I tried your sugestion but unfortunately could not get it to work.
I tried the approach in the link below - it doesn't always expand all hierarchies either.
http://samples.infragistics.com/sldv/RunSamples.aspx?cn=pivot-grid#/pivot-grid/expand-hierarchies
Here is my code. If you see any inconsistencies/errors please let me know.
private void ExpandAll_Click(object sender, RoutedEventArgs e)
{
BackgroundWorker worker = new BackgroundWorker(); worker.DoWork += Worker_DoWork; worker.RunWorkerCompleted += (s, ee) => { this.pivotGrid.DataSource.DeferredLayoutUpdate = false; }; this.pivotGrid.DataSource.DeferredLayoutUpdate = true; worker.RunWorkerAsync(this.pivotGrid.DataSource);
}
ManualResetEvent manualResetEvent = new ManualResetEvent(false); void Worker_DoWork(object sender, DoWorkEventArgs e) { DataSourceBase dataSource = e.Argument as DataSourceBase; if (dataSource.Rows.Count > 0) { IFilterViewModel fvm = dataSource.Rows[0] as IFilterViewModel; if (fvm != null) { fvm.LoadFilterMembersCompleted += (sender1, e1) => { manualResetEvent.Set(); }; if (fvm != null && fvm.FilterMembers != null) { foreach (IFilterMember member in fvm.FilterMembers) { DrillIn(fvm, member); } } } } } private void DrillIn(IFilterViewModel filterViewModel, IFilterMember filterMember) { manualResetEvent = new ManualResetEvent(false); this.Dispatcher.BeginInvoke((Action)delegate() { filterMember.IsExpanded = true; }); if (filterMember.HasChildren && filterMember.FilterMembers.Count == 0) manualResetEvent.WaitOne(); foreach (IFilterMember member in filterMember.FilterMembers) { DrillIn(filterViewModel, member); } }
Hello,
I am just checking the progress of this issue and was wondering if you managed to achieve your goal or if you need any further assistance on the matter.
If the above suggestion helped you solve your issue please verify the thread as answered so other users may take better advantage of it.
I have been looking into your description and usually this exception is thrown when the collection you are “foreach”-ing is at the same time altered. I can imagine this being the case in your code since when expanding your ColumnHeaderCells they still do not have any children and the recursive call to your method is already called when the cells actually expand and receive children. This is when you get the exception. I can suggest you use the approach provided here: http://forums.infragistics.com/forums/p/47783/255156.aspx since it uses the UpdateLayout event which is called raised when the children have already been loaded.
Please let me know if you require any further clarification on the matter.