Database Programming Techniques > Accessing and Manipulating Cell Data > Reading and writing cell data within the current record |
You can read and write cell data within the current row by using the Column object's Text and Value properties. (The CellText and CellValue methods are used to read values from other, non-current rows.)
To examine cell data in the current row:
Example Title |
Copy Code
|
---|---|
CurrentText$ = TDBGrid1.Columns(ColIndex).Text CurrentValue = TDBGrid1.Columns(ColIndex).Value |
The Text and Value properties return the current contents of the specified column in the current row. Note that the contents may have been edited by the user. The Text property returns a formatted string (according to the column's NumberFormat property) exactly as it appears in the cell. The Value property returns the unformatted cell data as a string variant.
To change cell contents in the current row:
Example Title |
Copy Code
|
---|---|
TDBGrid1.Columns(ColIndex).Text = NewText$ TDBGrid1.Columns(ColIndex).Value = NewValue |
Since the Value property accepts a variant, you can supply the new data using any appropriate data type. For example, you can write a null value to the database by setting Value to Null in the BeforeUpdate event. You do not need to format NewText$ or NewValue, since the grid will perform the appropriate formatting before displaying the data.