Overview

The following classes, methods, and properties are required for using .NET controls in grid cells:

  • CellControl—This class represents a custom cell control and wraps any .NET control for use in a grid cell.
  • GridControl.RegisterControl—This method accepts a single argument, a System.Windows.Forms.Control-derived object, and returns an instance of a CellControl that wraps the .NET control.
  • Style.CustomControl—This property accepts a CellControl object created by GridControl.RegisterControl. The specified cell control object can then be used in grid cells using GridControl.SetStyleRange.

The following C# code segment illustrates how to use a .NET NumericUpDown as a cell editor in column 2 of a grid control. This should be executed only during or after the invocation of the GridControl.GridInitialized event.

 

// Instantiate a NumericUpDown control

System.Windows.Forms.NumericUpDown upDown =

new System.Windows.Forms.NumericUpDown();

 

// Configure the control

upDown.Minimum = -10;

upDown.Maximum = 10;

upDown.BorderStyle = BorderStyle.None;

 

// Instantiate a OBJECTIVE GRID FOR .NET Style object, and

// assign its CustomControl property to the registered CellControl

Style upDownCell = new Style();

upDownCell.CustomControl = this.GridControl1.RegisterControl(upDown);

upDownCell.Value = “0”;

 

// Use SetStyleRange to use the control in column 2

this.GridControl1.SetStyleRange(Range.Col(2), upDownCell);