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.