Features
The following sections describe features of the .NET cell control functionality in Objective Grid for .NET.
.NET Controls Can Be Used as Cell Editors
Any properly functioning .NET control can be used as a cell editor in Objective Grid for .NET. You can use the .NET controls shipped with Microsoft Visual Studio or create your own custom controls for use as cell editors. You can also embed a Objective Grid for .NET GridControl object in grid cells.
Using a .NET control as a cell editor requires the following four steps:
1. Create an instance of the .NET control that you want to use as a grid cell editor.
2. Register the control with the GridControl instance that will use it as a cell editor. Do this using the GridControl.RegisterControl method. It returns a CellControl instance.
3. Assign the resulting CellControl instance to the CustomControl property of a Style object.
4. Apply the Style to the GridControl using SetStyleRange.
Memory Resources Are Conserved
To conserve memory resources, only one instance of any .NET control is maintained for use as a grid cell editor. For example, if a .NET TextBox control is used as a cell editor for the entire grid table, only one instance of the TextBox control is maintained. It is automatically positioned, sized, initialized, and drawn in each cell as it becomes the current cell.
Style Manipulation Code Is Usually Not Needed
By default, the Text property for your .NET control is set to the Style.Value setting for the cell when it is initialized as the current cell. When cell editing is completed, the Text property for your control is stored back to the grid’s Style.Value property for the cell. This, in many cases, eliminates the need to write any style manipulation code.
Cell Control Behavior Can Be Monitored and Customized
The behavior of your .NET cell control can be monitored and customized using the various properties and events associated with the CellControl class. The following are examples of the kinds of behaviors that can be configured using CellControl properties and events:
Using the UseCellStyle property, the .NET CellControl can be displayed with the font, background color, and text color stored in the grid’s style for the cell. Conversely, the colors and font assigned to the .NET control can be used regardless of the stored style for the grid cell.
You can choose to be notified each time your .NET CellControl is drawn. This allows you do use GDI+ to draw inactive cells as desired. For example, a bitmap can be drawn in inactive combo-box cells to show that a combo box control is used in the cell.
You can choose to be notified of various editing events involving the cell control, including StartEditing, CancelEditing, EndEditing.
You can choose to be notified when the cell control is initialized as the current cell and when the cell contents need to be stored to the grid. By default, the .NET control’s Text property is used to initialize the cell and store the cell’s data. However, for more complicated controls, such as cells with an embedded GridControl object, you can use these events to write more complicated initialization and storage functionality.
Cell Editing Events Can Be Monitored
You can choose to handle cell editing events by monitoring the CellControl events directly or by monitoring the corresponding GridControl events. For example, the StartEditing event for a cell control can be monitored using the CellControl.StartEditing event or via the GridControl.StartEditing event.