Hi,
We allow our users to select columns by which to group a grid. We need to save their choice so as to be able to re-instate it later (automatically).
Could you please let me know how to programmatically (C#) retrieve columns by which a grid is currently grouped, and also how to programmatically group a grid by some columns? We use WinForms UltraWinGrid and WPF XamGrid, and I would really appreciate if you could provide code samples for both of them.
Thank you.
Best regards,
Adam
Mike,
I am happy with the solution as it is. As long as I capture the exception (and ignore it) the final layout, including grouping columns, is correct.
Thanks for your help.
Regards,
Well, if you are not using threading, then I'm afraid I can't explain the exception. Can you post a small sample project demonstrating this exception so we can check it out and debug it?
Hi Mike,
We do everything on the UI thread. The call to Invoke is redundant, I added it to to check if the exception still occurs. The exception happens intermittently when there are more than one GroupBy columns. For a single GroupBy column no exception occurs.
Hi Adam,
This won't work. Using an Invoke or BeginInvoke is good if you can do it all the time whenever information is passed across threads. But that's not the case here. You are not in control of the communication between the grid, the DataSource, and the BindingManager. So you cannot possibly do all of the proper marshalling that would be required in order to deal with the grid (or any bound control) while it is using DataBinding. DataBinding and threading just don't mix, except under some very rare and limited circumstances. There's a long, detailed discussion of this here:
Work with a dataset bound to a grid on a separate thread - Infragistics Community
Yes, we do use multi-threading. I did try to use grid.Invoke to explicitly execute the code on the UI thread but the problem persisted.