Skip to main content

Using a ComboBox as an editor

Comments

2 comments

  • Dapfor Team

    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
  • Phillip Piper

    Thanks. That works perfectly. I was missing the CellEditControl() call. 

    0

Please sign in to leave a comment.

Powered by Zendesk