Hi,
I'm trying to get a custom control to appear using a drop down button in a cell. I've found the HOWTO that tells you how to do this (http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=7698) but there is a problem.
The problem is that in my grid I have CellClickAction set to CellSelect (this is an absolute requirement), and with this setting the drop down button only works when the cell is in edit mode. The button is displayed but clicking on it has no effect and doesn't trigger any events (that I can find).
On columns with a standard drop down (using EditorWithCombo) the button functions without having to go into edit mode first.
Is there a way to get the drop down button connected to my custom control to work when CellClickAction is CellSelect?
Thanks,
John.
Hi John,
The cell has to enter edit mode in order to drop down. There's no way around that.
But there might be other ways to acheive what you want. Why does the CellClickAction have to be CellSelect? What are the requirements you are trying to satisfy?
I assume you don't want the user to be able to type into the cell. You could acheive the same thing by using UltraComboEditor, instead of UltraTextEditor and hiding the default dropdown button and replacing it with an EditorButton. Then you would simply set the Style of the column to DropDownList. This would prevent the user from typing into the cell, but still allow them to drop it down.
I need to be able to select cells (to allow apply actions to multiple cells in one go) or enter values for individual cells.
I use CellSelect to allow cells to be selected by simply clicking and dragging. For text cells I then manually control the entry into Edit mode. For standard drop down list cells clicking on the drop down button puts the cell into edit mode, I also manually enter edit mode to allow values to be selected by typing directly into the drop down.
This allows me to click on the cell to select it, or double-click, start typing, press return, press the drop down button, to edit (similar to Excel). I'm unable to get the same behaviour with the custom drop down because the button only functions when I go into edit mode. I need a cell where if I click on the cell part it selects the cell but if I click on the button it drops down my control.
Okay, so my suggestion won't work for you.
But.. as long as the button is displaying in the cell, there's another solution which should be pretty simple. The grid is selecting the cell when you click on the button. So all you have to do is trap for a MouseDown on that button and then enter edit mode and drop down the list yourself.CellClickAction only affects what happens when the user clicks the cell, it doesn't prevent you from putting the cell into edit mode programmatically.
Something like this:
private void ultraGrid1_MouseDown(object sender, MouseEventArgs e) { UltraGrid grid = (UltraGrid)sender; // Find the last UIElement that the mouse entered. UIElement element = grid.DisplayLayout.UIElement.LastElementEntered; if (element == null) return; // See if the element is an EditorButtonUIElement or if it's the child of one. EditorButtonUIElement editorButtonUIElement = element as EditorButtonUIElement; if (editorButtonUIElement == null) editorButtonUIElement = element.GetAncestor(typeof(EditorButtonUIElement)) as EditorButtonUIElement; if (editorButtonUIElement == null) return; // Get the button from the element. DropDownEditorButton dropDownEditorButton = editorButtonUIElement.Button as DropDownEditorButton; if (dropDownEditorButton != null) { // Enter edit mode and drop down. grid.PerformAction(UltraGridAction.EnterEditMode); dropDownEditorButton.DropDown(); } }
There's a bit of a flicker when I do this on my machine. The cell get selected and then enters edit mode and the text gets selected and then it finally de-selects the text and drops down. You might be able to get it to look cleaner using MouseUp instead of MouseDown. Or maybe using a BeginInvoke to call the PerformAction and DropDown methods. But it does work.
Yep that works for me.