I have a WinForms UltraGrid bound to a data source. Above the grid I have some controls which I want to align with specific columns underneath.
When a column's width is resized I want the controls above to resize too.
Initially I achieved this using the PropertyChanged event:
if (e.ChangeInfo.FindPropId(Infragistics.Win.UltraWinGrid.PropertyIds.Width) != null) { if (e.ChangeInfo.FindPropId(Infragistics.Win.UltraWinGrid.PropertyIds.Header) != null) { // REPOSITION CONTROLS USING WIDTHS OR VISIBLE COLUMNS TO CALCULATE LOCATION } }
However once I set the grid AutoFitStyle to ResizeAllColumns the controls will not align correctly anymore.
e.Layout.AutoFitStyle = Infragistics.Win.UltraWinGrid.AutoFitStyle.ResizeAllColumns;
Is there a more appropriate event to handle for this behaviour or someway of making it work when the AutoFitStyle is set to ResizeAllColumns?
Thank you Mike and Ivaylo for your help as always.
Using the PropertyChanged event works great.
My problem was I was handling both the PropertyChanged and AfterColPosChanged events with the AfterColPosChanged running after the PropertyChanged and messing up the column widths.
All sorted now though.
Thanks,Paul
Hello Paul,
I am just checking about the progress of this issue.
Did you solve your issue accordingly to the information that I provided you?
Let me know if you need any further assistance.
Thank you for using Infragistics Components!
As Mike already mentioned you should be aware of couple of things before synchronizing all of the controls, especially when AutoFitStyle is set to ResizeAllColumns. Definitely your approach using UltraGrid’s PropertyChanged event handler is the right way to go in this case. Using AfterColPosChanged event is useful, but it would be much harder to accomplish completely synchronized columns and controls rectangles.
I have modified my sample to use UltraGrid’s PropertyChanged. Synchronizing columns headers and controls is done by initializing custom delegate which invokes thread-safe method. Everything seems to be working smoothly now as columns and controls rectangles are adjusted as per your requirements.
I am waiting for your feedback.
Hi,
Can you be more specific about exactly what's not working?
Once you turn on the AutoFitStyle, changing the size of any one column can potentially affect all of the other columns (or at least one or more other columns). So is the issue here that you are only updating the control for the one column for which the event fired? Or arr you resizing all of your synchronized controls every time?
It seems to me that you have to synchronize all of the controls every time.
If that's not working, then I can think of two things that might be going wrong.
1) There's a timing issue - the event may be firing before all of the column sizes have been calculated. If that's the case, then you can probably work around it by moving the code outside the event handler into a method and then calling that method via a BeginInvoke. That will create a delay between when the event is fired and when you code executes.
2) You might not be retrieving the right size. I'm pretty sure the Width property of the last column will not return the actual on-screen width of the column, because the stretching of the column doesn't affect the width. To get the real size, using column.CellSizeResolved.Width.
Thank you for your response.
The problem with your solution is that it only changes the size of the control related to the column which has been resized.
With AutoFitStyle set to ResizeAllColumns all the columns widths are changed when you resize any column and as such all the related controls should resize.
In my experience simply resizing all the columns in band directly causes the resize to appear to be a step behind.