Using a ComboBox as an editor
I know this sounds simple, but I haven't been able to make a ComboBox into an editor. Could you please show me an example of how to do that?
More generally, we have many cases where we want our users to be able to type into a cell in place, and have their typing auto completed from a fixed list of values.
This is different to the current EnumerableEditor in that the EnumerableEditor doesn't auto complete, and it always shows the full list.
1
-
Hello Phillip,
.Net Grid supports any controls in cells. Below you'll find an example how to implement this feature:
class MyCustomEditor : UITypeEditorEx
{
public override StopEditReason EditCell(IGridEditorService service, Cell cell, StartEditReason reason)
{
//Create a control to be displayed in the cell
using(ComboBox myBox = new ComboBox())
{
//Set some initial parameters
myBox.Items.Add("Item1");
myBox.Items.Add("Item2");
myBox.Items.Add("Item3");
//Add reaction on user input
myBox.SelectedIndexChanged += delegate
{
//Ask the service to close the control and leave the Application.DoEvents() loop
service.CloseCellControl(StopEditReason.UserStop);
//Apply the value
cell.Value = myBox.Text;
};
//Begin cell editing. This is a blocking method with internal Application.DoEvents() loop.
StopEditReason stotReason = service.CellEditControl(myBox, cell.VisibleBounds, reason);
//return from the editing procedure.
//The 'using' statement will call the Dispose() method of the combobox
return stotReason;
}
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
//This style indicates that the control should be placed directly in a cell
return UITypeEditorEditStyle.None;
}
}
//This code installs the editor
grid.Headers[0]["column id"].Editor = new MyCustomEditor();Best regards,
Dapfor
0 -
Thanks. That works perfectly. I was missing the CellEditControl() call.
0
Please sign in to leave a comment.
Comments
2 comments