Set of cell editors.

Classes

  ClassDescription
Public classAppearanceEditor
A dropdown editor to edit Appearance object
Public classBoolEditor
A dropdown editor to edit boolean values.
Public classCheckBoxEditor
A checkbox editor to edit boolean values in cells.
Public classConvertibleValueEditor
Embedded textbox editor that edit values of primitive types (int, double, etc.) in cell.
Public classDropDownEditor
Base class for dropdown editors
Public classEditorPicker
Enables to select an available UITypeEditor.
Public classEditorProvider
Provides System and default Dapfor editors
Public classEnumEditor
A dropdown editor to edit values of Enum type
Public classEnumerableEditor
A dropdown editor to edit IEnumerable values
Public classFormatEditor
Edits StringFormat object
Public classMessageQueueHelper
Provides static methods and properties to process Windows messages. This class cannot be inherited.
Public classTrackBarEditor
TrackBar editor to edit numeric values.
Public classUITypeEditorEx
Extension of UITypeEditor that enables painting in cells and creating any controls over cells.
Public classUpDownNumericEditor
UpDown editor to edit numeric values

Interfaces

  InterfaceDescription
Public interfaceIGridEditorService
Enables value editing via editors created over cells

Enumerations

  EnumerationDescription
Public enumerationStartEditReason
Initial cause of cell editing
Public enumerationStopEditReason
Indicates why cell editing is interrupted

Remarks

.Net Grid supports multiple ways of cell editing. When we were developing this mechanism, we based it on standard editors used in the PropertyGrid control.

There are several types of these editors including controls that can be displayed in a dropdown box or as a modal dialog. Such editors enable users to edit text, colors and enumerations and to perform painting in small rectangles inside cells. There are plenty of predefined editors. For example, you can get the color editor as follows:

 Copy imageCopy
UITypeEditor editor = (UITypeEditor)TypeDescriptor.GetEditor(typeof (Color), typeof (UITypeEditor));

To edit values, these editors use the UITypeEditor.EditValue(...) method. Within this method a mandatory control is created and placed in the dropdown box. You should note a very important detail the return from the function UITypeEditor.EditValue(...) occurs only when editing within in the control is completed, which is convenient from the programmer's point of view. Look at this example:

 Copy imageCopy
object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
    IWindowsFormsEditorService service = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
    using (SomeControl control = new SomeControl(value))
    {
        service.DropDownControl(control);
        value = control.NewValue;
    }
    return value;
}

The .Net Grid fully supports this mechanism and editors of other vendors that can be used in your applications.

Despite the convenience of this interface, we have concluded that it lacks some functionality. These editors can't be created above the edited cell with its size (for example, slider control). Besides that, they can't be painted in the whole cell just in a small rectangular area. To remediate this, we have created UITypeEditorEx a class, derived from UITypeEditor that allows to create controls directly above a cell. The process of editing is quite similar to the aforementioned code example.

 Copy imageCopy
StopEditReason EditCell(IGridEditorService service, Cell cell, StartEditReason reason)
{
  using (SomeControl control = new SomeControl(cell))
  {
    return service.CellEditControl(control, cell.VirtualBounds, reason);
  }
}

Besides, some editors can be used without creating graphic controls, i.e. a rating editor. It simply draws stars, and when the user clicks on a certain star, this control calculates its relative location and sets a new value. The whole editing code will look as follows:

 Copy imageCopy
StopEditReason EditCell(IGridEditorService service, Cell cell, StartEditReason reason)
{    
    //compute a new rating
    cell.Value = rating ;
    return StopEditReason.UserStop ;
}

Example of an easy drop-down editor where the end-user can click on the push button
 Copy imageCopy
public class CustomEditor : UITypeEditor
{
    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
    {
        // Uses the IWindowsFormsEditorService to display a drop-down UI in the grid. (See more System.Drawing.Design.UITypeEditor)
        IWindowsFormsEditorService service = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));

        //The result to be returned
        object result = value;

        //Create some UI control
        Button button = new Button();
        button.Click += delegate
        {
            //result = ... <new value>
            service.CloseDropDown();
        };
        //Do edit in place in the editor service. If the end user clicks on the button, then the callback will be called.
        service.DropDownControl(button);

        return result;
    }

    public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
    {
        //The style is drop-down list box
        return UITypeEditorEditStyle.DropDown;
    }
}


//Some data object
public class Car 
{
    //Some fields
    private double price;
    private double maxSpeed;
    private Color color;

    //Declaration of the CustomEditor. This declaration is also used by the System.Windows.Forms.PropertyGrid, so your object 
    //can be edited in the same way in various grids. 
    [Editor(typeof(CustomEditor), typeof(UITypeEditor))]
    public double MaxSpeed
    {
        get { return maxSpeed; }
        set { maxSpeed = value; }
    }

    //The declaration of the Editor can be done in the column
    public double Price
    {
        get { return price; }
        set { price = value; }
    }

    //Default color editor is used (System.Drawing.Design.ColorEditor). 
    //This editor is returned by the TypeDescriptor.GetEditor(typeof (Color), typeof (UITypeEditor)) call; 
    public Color Color
    {
        get { return color; }
        set { color = value; }
    }
}

//Initialize the grid
public void AddDataObjectToGrid(Grid grid)
{
    //Configure the headers
    grid.Headers.Add(new Header());
    grid.Headers[0].Add(new Column("MaxSpeed"));
    grid.Headers[0].Add(new Column("Price"));
    grid.Headers[0].Add(new Column("Color"));

    grid.Headers[0]["MaxSpeed"].Editable = true;
    grid.Headers[0]["Price"].Editable = true;
    //Declare the editor only for the current grid
    grid.Headers[0]["Price"].Editor = new CustomEditor();
    grid.Headers[0]["Color"].Editable = true;

    //Add a data object
    grid.Rows.Add(new Car());

    //Edit the cell programmatically
    grid.Rows[0]["Price"].Edit();

    //...
}