Hi,
I have made a custom column that consists out of an EditorWithText editor and a DropDownEditorButton as one of its editorbuttons. When the editorbutton is clicked, an UltraGrid is opened. This is done so I can make use of the filterrow.
Everything works fine. But now I want to open the grid when the control gets into to edit mode, either by tabbing into it or by clicking it.
As you can see in the code(below) I've added a handler to the editor's AfterEnterEditMode. In the handler, I make the call to the DropDownEditorButton's Dropdown() method. The handler I placed on the dropDownbutton's BeforeDropDown event is called, so the DropDown method did something, but after that nothing happens. No Grid, no nothing. But when I click on the dropdown button, I do see a grid.
I have seen multiple post where people have this problem and the solution there was to cast the active cell's EditorResolved of the grid to EmbeddableEditorButtonBase. Then cast the EmbeddableEditorButtonBase's editorbutton to an DropDownEditorButton and call DropDown(). But this does not work for me.
Are there any other suggestions?
Code:
_grid = New ePosDataGrid() _grid.Height = 300 _grid.HasFilterRow = True _grid.DisplayColumns = Me.DisplayColumns _grid.DataSource = Me.DataSource _grid.Base.DisplayLayout.Override.FilterEvaluationTrigger = FilterEvaluationTrigger.OnCellValueChange _dropDownButton = New DropDownEditorButton() With {.Control = _grid} _dropDownButton.Key = "CustomActivityDropDownButton" AddHandler _dropDownButton.AfterCloseUp, AddressOf dropDownButton_AfterCloseUp AddHandler _dropDownButton.BeforeDropDown, AddressOf dropDownButton_BeforeDropDown Dim editor As New EditorWithText(New DefaultEditorOwner()) AddHandler editor.AfterEnterEditMode, AddressOf editor_AfterEnterEditMode column.Editor = editor
Private Sub editor_AfterEnterEditMode(sender As Object, e As EventArgs) _dropDownButton.DropDown() End Sub
I tried this out using your code and I got the same results. The drodpown is actually dropping down, but then it closes up again almost instantly. This is probably a timing issue. The cell enters edit mode, you drop down the list, and then the cell displays a TextBox over itself and focuses the TextBox which pulls focus from the dropdown and closes it.
To get around this, you have to create a delay so that the cell can finish it's own processing before dropping down the list. This worked for me:
Private Sub editor_AfterEnterEditMode(sender As Object, e As EventArgs) Me.UltraGrid1.BeginInvoke(New MethodInvoker(AddressOf Me.ShowDropDown)) End Sub Public Sub ShowDropDown() Dim editor As EmbeddableEditorButtonBase = Me.UltraGrid1.ActiveCell.EditorResolved Dim dropDownEditorButton As DropDownEditorButton = editor.ButtonsRight(0) dropDownEditorButton.DropDown() End Sub
Thanks Mike!!! That fixed the problem :D
Another, it is related, question. Let say I get an UltraGridColumn as an argument, is there any way the check if this column is associated to a ultraWinGrid? if so, how could I get the associated grid from that argument?
Haha :D. I knew there was something easier, I just couldn't find it. Thanks Mike.
column.Band.Layout.Grid
This actually returns an UltraGridBase, but you can cast it to an UltraGrid.
Well I got something through reflection. It is not pretty, but it works. if there is an easier way, let me know.
code:
Private Function GetGridFromColumn(column As UltraGridColumn) As UltraGrid Dim grid As UltraGrid = Nothing Dim propEditorOwnerInfo = column.GetType().GetProperty("EditorOwnerInfo", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance) Dim typeEmbeddableOwnerInfo = System.Reflection.Assembly.GetAssembly(GetType(UltraGridColumn)).GetType("Infragistics.Win.UltraWinGrid.EmbeddableEditorOwnerInfo", False, True) If (propEditorOwnerInfo IsNot Nothing AndAlso typeEmbeddableOwnerInfo IsNot Nothing) Then Dim cast = Convert.ChangeType(propEditorOwnerInfo.GetValue(column, Nothing), typeEmbeddableOwnerInfo) Dim propGrid = typeEmbeddableOwnerInfo.GetProperty("Grid", Reflection.BindingFlags.NonPublic Or Reflection.BindingFlags.Instance) If (propGrid IsNot Nothing) Then grid = TryCast(propGrid.GetValue(cast, Nothing), UltraGrid) End If End If Return grid End Function