ComponentOne True DBGrid for .NET (2.0) Search HelpCentral 

Using Custom Editors

The built-in editors provide a lot of flexibility and power, but in some cases you may want to use external controls as specialized editors. For example, you may want to use the C1NumericEdit control that provides a drop-down calculator for entering numbers, or an editor for selecting from multi-column lists, or a specialized control that you wrote to edit your business objects.

Note: The C1NumericEdit control is one of the Input for .NET controls. For more information on the C1NumericEdit control, please refer to the Input for .NET documentation.

Any control that derives from the base Control class can be used as a basic grid editor. Controls that implement the IC1EmbeddedEditor interface can provide better integration with the grid and more advanced features. For details on the IC1EmbeddedEditor interface, see the Editor property.

To use a control as a custom editor, all you have to do is associate an instance of the control with a grid column using the Editor property. You can do this in code using the Editor property. After that, the control will be automatically used by the grid.

For example, to use a C1NumericEdit control as a grid editor, follow these steps:

1.   Add a C1TrueDBGrid control and a C1NumericInput control to the form.

2.   For the C1NumericInput control, set the BorderStyle property to None and the Visible property to False either in the Properties window or by adding the following code to the Form_Load event:

·      Visual Basic

' Set up the custom editor.

Me.C1NumericEdit1.BorderStyle = BorderStyle.None

Me.C1NumericEdit1.Visible = False

·      C#

// Set up the custom editor.

this.c1NumericEdit1.BorderStyle = BorderStyle.None;

this.c1NumericEdit1.Visible = false;

·      Delphi

// Set up the custom editor.

Self.C1NumericEdit1.BorderStyle := BorderStyle.None;

Self.C1NumericEdit1.Visible := False;

3.   In the From_Load event assign the custom editor to the grid column.

·      Visual Basic

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

    ' Assign the custom editor to the grid.

    Me.C1TrueDBGrid1.Columns(0).Editor = Me.C1NumericEdit1

End Sub

·      C#

private void Form_Load(object sender, EventArgs e)

{

 

    // Assign the custom editor to the grid.

    this.c1TrueDBGrid1.Columns[0].Editor = this.c1NumericEdit1;

}

·      Delphi

procedure TWinForm.TWinForm_Load(sender: System.Object; e: System.EventArgs);

begin

 

  // Assign the custom editor to the grid.

  Self.C1TrueDBGrid1.Columns[0].Editor := Self.C1NumericEdit1;

end;

Run the project and edit some values in the first column. Notice how the grid positions and initializes the C1NumericEdit control so you can edit cell values. When you are done editing a cell, click a different cell, or press the TAB key to move to the next one. Notice how the new value is applied to the cell.


Send comments about this topic to ComponentOne.
Copyright © ComponentOne LLC. All rights reserved.