Storage Mode > Interactions between True DBGrid and XArrayDB > Inserting and removing XArrayDB rows |
When inserting or deleting rows, you must ReBind the grid afterwards, since it does not receive any notifications from the XArrayDB object. Note that a grid Refresh is not sufficient in this case, since the dimensions of the XArrayDB object have been changed.
The following example implements a command button that inserts a new row before the current grid row, then sets focus to the grid:
Example Title |
Copy Code
|
---|---|
Private Sub Command1_Click() With TDBGrid1 MyArray.InsertRows .Bookmark .ReBind .SetFocus End With End Sub |
The InsertRows method requires a row index argument that specifies the position of the new row. This method also accepts an optional second argument that specifies the number of rows to insert. If omitted, this argument defaults to 1.
When a new row is inserted, all subsequent rows are shifted to make room for it. That is, if you insert a row at index position 6, the former row 6 becomes row 7, the former row 7 becomes row 8, and so forth.
To add one or more rows to the end of an XArrayDB object, use the AppendRows method. This method accepts one optional argument that specifies the number of rows to append. If omitted, this argument defaults to 1.
To delete the current row, you could use the DeleteRows method of XArrayDB, then ReBind the grid. However, the Delete method of the grid provides a more direct way of accomplishing the same task.
Note: For backward compatibility, the Insert and Delete methods of the original XArray object were retained in XArrayDB.