I would like to auto-set the size of a combo column (as is the only one visible in the combo) to be at least equal to the combo actual Width, but not less equal that the tallest string in that column rows.
How to do it?
My code actually:
Private Sub cmb_InitializeLayout(ByVal sender As System.Object, ByVal e As Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs) Handles cmbObject.InitializeLayout
Dim combo As UltraCombo = TryCast(sender, UltraCombo) If combo IsNot Nothing AndAlso combo.DisplayLayout.Bands.Count > 0 Then If combo.DisplayLayout.Bands(0).Columns.Count > 1 Then combo.DisplayLayout.Bands(0).Columns(0).Hidden = True combo.DisplayLayout.Bands(0).Columns(1).PerformAutoResize(PerformAutoSizeType.AllRowsInBand) End If End If End Sub
Instead of PerformAutoSize, you can use the CalculateAutoResizeWidth method. This method does essentially the same thing as PerformAutoSize, except that it does not change the Width of the column - it just returns the Width to you.
Then you can set the Width of the column to the Max of the returned width and the width of the control.
I tried
Private Sub cmb_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbObject.Resize Dim combo As UltraCombo = TryCast(sender, UltraCombo) If combo IsNot Nothing AndAlso combo.DisplayLayout.Bands.Count > 0 Then If combo.DisplayLayout.Bands(0).Columns.Count > 1 Then With combo.DisplayLayout.Bands(0).Columns(1) .Width = Math.Max(.CalculateAutoResizeWidth(PerformAutoSizeType.AllRowsInBand, False), combo.Bounds.Width) End With End If End If End Sub
but this does not work after the DataSource of the combo is changed..
Just because the Resize event is not fired when a dataSource changes, the code I wrote will not be executed when a DataSource will change, so any Width modification will not happen, so, when you will do the DropDown, the column width will remain as under the ancient DataSource (ar last Resize).
After the DataSouce changes I need to do a resize in order to "update" my desired width.
In fact, I need to run the same code in the event like "_DataSourceChanged" if any...
Okay, but as I said, the Resize event will not fire when you change the DataSource on an UltraCombo. Resize only fires when the size of the control changes. That is, the size of the edit portion of the control on the form, not the DropDown. You should probably be using the BeforeDropDown event or maybe IniitalizeLayout.
When dataSource is changed, data changes, strings changes, so, the ancient size became obsolete... So just Resize is not enough as event to update the Width.
What do you mean "does not work"?
What is happening? Is this code even called when the DataSource of the combo is changed? I don't see why the Resize event would even fire in that case.