You can modify a grid cell value by inputting the desired value directly into the cell. In order to do that, you first need to locate the desired cell within the grid, select it and activate its in-place editor. After the cell's in-place editor is activated, you can “type” data in the cell by simulating keystrokes. Below is a sample that demonstrates how to do this.
The sample code contains the following routines:
Main - The “main” routine of the sample. It obtains the scripting object that corresponds to the grid window and then calls the
SetCellByKeys routine to change the cell value.
SetCell - Activates the in-place editor and “enters” the data by simulating the appropriate keystrokes. To confirm the change, the routine also simulates the ENTER keystroke.
SetCellByKeys routine uses four parameters:
- GridObject -- specifies the tested TDBGrid control.
- Row and Col -- the row and column indexes of the desired cell. Both indexes are zero-based, that is, we assume that the top-left data cell of the grid has (0, 0) for indexes.
- NewValue -- the value to be entered in the cell. Since we “type” values by simulating keystrokes, the NewValue parameter must be a string value.
Note: After activating the in-place editor, the cell's data is selected, so, the sample script will replace the cell value with the new value.
ActivateCellEditor - Activates the in-place editor of the specified cell.
SelectCell - Moves focus to the specified cell.
ActivateRow - Selects a row in the TDBGrid control.