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?
Hello Paul,
Thank you for contacting Infragistics!
As far as I understand your goal is to bind UltraGrid’s column width to another control’s one and on column’s resizing the effect to be applied to the bound control.
In order to accomplish similar behavior I recommend you the following approach and it works flawlessly with any UltraGrid AutoFitStyle. On Initializing UltraGrid’s layout all columns and controls widths are synchronized. UltraGrid has AfterColPosChanged event which is raised when any column is moved, resized or swapped. Looking through the arguments will tell you which exactly column has been resized. This allows you to adjust any control’s width based on the resolved size of the column.
For further reference about using AfterColPosChanged, please see the following documentation page: http://help.infragistics.com/Help/Doc/WinForms/2011.2/CLR2.0/html/Infragistics2.Win.UltraWinGrid.v11.2~Infragistics.Win.UltraWinGrid.UltraGridBase~AfterColPosChanged_EV.html
Please download and take a look at the attached sample. You can find my solution explained and implemented. If my approach doesn’t fit your requirements, please feel free to modify the sample and/or ask me any additional questions.
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.
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!
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