Hi.
I have an UltraCombo that is assigned to a grid cell EditorControl. Everything works as planned, except for one thing: The UltraCombo grid column does not auto size to the drop down.
I have tried setting the relevant AutoSize on the column and AutoFitStyle on the control without luck.
What am I missing here?
Best regards,
Goran
CType is "Convert to type". It's just like casting in C#.
So:
editorElem = CType(buttonElem.ChildElements(0), EditorWithComboUIElement)
is the same as:
editorElem = (EditorWithComboUIElement)buttonElem.ChildElements(0);
Thanks for the code example! I had to convert to C# though, as this project is using it (see below).
Also, I didn't know how to convert your Ctype methods above, so I just used a foreach loop, i'm sure there is something more elegant, but its probably doing the same thing anyway.
also, my situation was a little different, we put this code in all of our drop down controls (in grids and on forms) on the "BeforeDropDown" event, so we really don't have a handle to the UltraGrid, but the UIElement was available for us to use.
Infragistics.Win.EditorWithComboUIElement editorElement = null; Infragistics.Win.EditorWithComboDropDownButtonUIElement comboElement = null; Infragistics.Win.EditorWithTextUIElement text = null; try { foreach (var element in UIElement.ChildElements) { if (element is Infragistics.Win.EditorWithComboUIElement) editorElement = (Infragistics.Win.EditorWithComboUIElement)element; } if (editorElement != null) { foreach (var element in editorElement.ChildElements) { if (element is Infragistics.Win.EditorWithComboDropDownButtonUIElement) comboElement = (Infragistics.Win.EditorWithComboDropDownButtonUIElement)element; if (element is Infragistics.Win.EditorWithTextUIElement) text = (Infragistics.Win.EditorWithTextUIElement)element; } if (comboElement != null) buttonWidth = comboElement.Rect.Width; } } catch (Exception) { }
Here is a small code example of how I did it:
Private Sub myGrid_BeforeCellListDropDown(ByVal sender As Object, _ ByVal e As CancelableCellEventArgs) _ Handles myGrid.BeforeCellListDropDown
Dim tmpDD As StandardDropDown 'This is actually an UltraComboDim btnWidth As Integer = 20Dim buttonElem As UIElementDim editorElem As EditorWithComboUIElementDim comboElem As EditorWithComboDropDownButtonUIElement'Get ref to dropdowntmpDD = CType(e.Cell.EditorComponentResolved, StandardDropDown) Try 'Get UIElement from cell buttonElem = e.Cell.GetUIElement() 'Get main editor element editorElem = CType(buttonElem.ChildElements(0), EditorWithComboUIElement) 'Get actual editor (UltraCombo) element
comboElem = CType(editorElem.ChildElements(0), EditorWithComboDropDownButtonUIElement) 'Set button width to with of editor button width btnWidth = comboElem.Rect.Width + DROPDOWNBUTTON_WIDTH_COMP 'const to adjust width, it misses by a few pixels for some reason Catch Throw End Try If tmpDD IsNot Nothing Then 'Adjust with of grid column in drop down tmpDD.DisplayLayout.Bands(0).Columns("Name").Width = e.Cell.Column.CellSizeResolved.Width - btnWidth End If
End Sub
Mike,
could you provide a small code example for what you described above? I too need to get the drop down button widths.
it seems to be different for grids and controls so if I can grab the actual value that would be preferred.
Thanks for the tip. I ended up using the ChildElements collection and drill down to the correct element. Then I used the Rect property to get the width. Works great. Thanks again!