Working With TDBGrid - Setting Cell Values
Test and Monitor | Posted April 01, 2007

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.

    The 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.
Close

By submitting this form, you agree to our
Terms of Use and Privacy Policy

Thanks for Subscribing

Keep an eye on your inbox for more great content.

Continue Reading

Add a little SmartBear to your life

Stay on top of your Software game with the latest developer tips, best practices and news, delivered straight to your inbox