Is there a best-practice to set up a column so that it will allow the user to click its drop-down button and interact with a popup control while _dis_allowing the user from editing the cell's value by using the keyboard?
We're displaying formatted data in the cell (derived ToString()) and popping up a UserControl that contains all the ui to edit the object attached to the cell's .Value.
Thanks
Set the Style property of the corresponding column to "DropDownList". This prevents the user from typing free text into the cell, while allowing them to choose values from the drop-down list.
We tried that Vince, it didn't work as expected when I have a UserControl attached to the .EditorControl property.
We're using Infragistics.Win.UltraWinEditors.UltraTextEditor
Thanks. Would it be accurate to assume that you've added a DropDownEditorButton to either the ButtonsRight or ButtonsLeft collection of your WinTextEditor, and that you've set the Control property of this DropDownEditorButton to an instance of your user control?
I'm looking into possible solutions. There's no automated option that I can quickly find that would give you behavior similar to using a ColumnStyle of DropDownList. It might be possible with a combination of other property settings, by handling certain events on the grid (such as to prevent keystrokes from being passed to a cell's text when a cell in this column is in edit mode), or possibly both.
Yes, that is an accurate description of what we've done. Precisely, we have added to the ButtonsRight collection.
You can't do this with an UltraTextEditor, but you can do it with an UltraComboEditor. Here's how you do it.
First, you need to remove the default dropdown button from the combo and replace it with a DropDownEditorButton in the ButtonsRight collection - just like you did with the UltraTextEditor.
this.ultraComboEditor1.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never; DropDownEditorButton dropDownEditorButton = new DropDownEditorButton(); dropDownEditorButton.Control = this.button1; this.ultraComboEditor1.ButtonsRight.Add(dropDownEditorButton);
In the InitializeLayout event of the grid, attach the UltraComboEditor to the column and set the Style to DropDownList:
private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e) { UltraGridLayout layout = e.Layout; UltraGridBand rootBand = layout.Bands[0]; rootBand.Columns["String 1"].EditorControl = this.ultraComboEditor1; rootBand.Columns["String 1"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; }
If you run the application and click on the dropdown, you will see the whole cell gets highlighted and you can't type. But there are a couple of problems. The first problem is that if you click on the cell instead of the button, the default (empty) dropdown of the UltraComboEditor shows up. So you need to cancel that and show your button dropdown instead:
private void ultraGrid1_BeforeCellListDropDown(object sender, CancelableCellEventArgs e) { if (e.Cell.Column.Key == "String 1") { e.Cancel = true; EditorWithCombo editor = (EditorWithCombo)e.Cell.EditorResolved; DropDownEditorButton dropDownEditorButton = (DropDownEditorButton)editor.ButtonsRight[0]; dropDownEditorButton.DropDown(); } }
The second problem is that when you are using DropDownList style, the grid will not permit the cell to have a Value that does not exist on the list. So if the user chooses a value from your DropDownButton and tries to leave the cell, they will get an error.
So you are going to have to populate the UltraComboEditor's "real" list with a list of all possible values. Or, any time the user chooses something from your dropdown control, add the item to the list at that point.
Thanks Mike, that works.