Using .NET Cell Controls
The following C# code shows the simplest use-case for using a .NET control in a grid cell. It illustrates the use of a .NET TextBox in grid cell 1, 1.
 
// Instantiate a Style object. Set the CustomControl property
// to a registered TextBox control. Then, set the resulting style
// for grid cell 1,1.
Style s = new Style();
s.CustomControl = this.GridControl1.RegisterControl(new TextBox);
this.GridControl1.SetStyleRange(Range.Cell(1, 1), s);
You can dramatically customize the behavior of .NET cell controls using the following mechanisms:
*You can set properties of the TextBox before registering it with the GridControl. You can also attach delegates to the .NET control for event handling purposes. Finally, you can write your own custom .NET control for use as a cell editor.
*You can customize the CellControl instance returned from GridControl.RegisterControl. CellControl exposes a number of public properties and events that can be used to customize the behavior of the cell controls. For more detailed information about these properties and events, see CellControl in the Objective Grid for .NET® Reference Guide.
Table 26 lists and describes the public properties available for the CellControl class.
Table 26 – Cell Control Properties 
Property
Description
DrawInactiveCell
Gets or sets a value that is true if you want the grid to draw inactive cell contents. When you are drawing inactive cells, set the value to false.
Grid
Gets the GridControl with which this custom control is associated.
ProcessHorizontalArrows
Gets or sets a value that is true if your custom control processes horizontal arrow key events. If false, the right and left arrow keys move the current cell in the corresponding direction.
ProcessVerticalArrows
Gets or sets a value that is true if your custom control processes vertical arrow key events. If false, the up and down arrow keys move the current grid cell in the corresponding direction.
UseCellStyle
Gets or sets a value that indicates whether the cell style from the grid should be applied to the custom control. If true, the font, background color, and text color stored in the grid are applied to the control when it is initialized as the current cell. If false, the settings applied to the .NET control are used to display the control.
Table 27 lists and describes the public events available for the CellControl class. For each of these events, a corresponding On event handler raises the event. Each On event handler is invoked by the grid, and in turn, the event handler raises the event, invoking any delegates that you may have attached to the event.
For more detailed information describing the default processing associated with each of these events, see CellControl in the Objective Grid for .NET® Reference Guide.
Table 27 – CellControl Events
Event
Description
CanceledEditing
This event is raised when the current cell’s contents are canceled and the control has been reinitialized.
CancelEditing
This event is raised when the user has pressed ESC on the current cell.
DrawCellControl
This event is raised each time this CellControl is drawn, which depends mostly upon whether the cell is the current cell. The event arguments for this event indicate whether the cell is the current cell. At this time, this event is intended to notify when cells are drawn and to allow the end user to implement custom drawing logic for inactive cell controls.
EndEditing
This event is raised when the user confirms the cell’s data, and the data is valid. You are given the opportunity to indicate whether the data are accepted via the event arguments.
HideCurrentCell
This event is raised when the CellControl should be hidden.
InitCurrentCell
This event is raised by GridControl when the intrinsic state (for example, row, column, and Style*) of the control for the current cell needs to be initialized. It is invoked when the current cell has moved and the CellControl is being initialized as the new current cell.
LeftCell
This event is raised after the current cell is deactivated. At the time this event is raised, the grid does not have a current cell. You can attach a delegate to this event if you want to control the refreshing of the current cell after it is deactivated.
ModifyCell
This event is raised when the user modifies the cell’s contents.
RefreshCurrentCell
This event is raised when the cell needs to be refreshed.
ResetCurrentCell
This event is raised when the grid resets the intrinsic state of the control. This happens when the current cell is moving.
StartEditing
This event is raised when the user starts editing the cell by pressing a key or moving the mouse.
StoreCurrentCell
This event is raised to store the cell’s data to the grid. For efficiency, this method is raised only if the cell contents are modified. For your convenience, the cell is marked as modified as part of the event handling for the StartEditing event.
ValidateCell
This event is raised to validate the contents of a grid cell.