Log In
[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Collapse]Data Grid
   [Expand]Getting Started
   [Expand]Binding to Data
   [Expand]Grid View
   [Expand]View Technology
   [Collapse]Data Editing
    [Expand]Edit Form
    [Collapse]Editing via Code
      Adding and Deleting Records
      Obtaining and Setting Cell Values
      Refreshing the GridControl
    [Expand]In-place Editors
    [Expand]Input Validation
    [Expand]New Item Row
     Tutorial: Add or Remove Rows
     Tutorial: Data Input Validation
   [Expand]Filtering and Locating Rows
   [Expand]Focus and Selection Handling
   [Expand]Processing Rows
   [Expand]Formatting Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
   [Expand]Batch Modifications
   [Expand]Hit Information
   [Expand]Popup Menus
   [Expand]Saving and Restoring Layouts
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Document Server
[Expand]Report Server
[Expand]eXpressApp Framework
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Adding and Deleting Records

Views provide several methods for manipulating records in a bound data source. This section describes methods for adding and deleting records. The Obtaining and Setting Cell Values document shows how you can access cell values.

Expanded Online Video

  • Add or Remove Rows
    This video describes the Grid Control's UI elements and API that enable you and end-users to add or remove data rows. You will first learn how to enable the built-in Data Navigator, then how to use the Microsoft Outlook inspired New Item Row to add new records. Finally, the video will show you the basic API that enables you to add or delete rows, and also initialize field values when end-users add records using the Grid Control's UI

Expanded General Information

First though, you can always use methods of your data source to add, delete and modify individual rows. Some data sources (for instance, arrays and read-only collections) do not support adding or deleting rows. Others introduce properties to prevent modifications. For instance, when using data sources implementing the System.ComponentModel.IBindingList interface, you can only delete rows if the IBindingList.AllowRemove property is set to true and only add rows if the IBindingList.AllowNew property returns true.

In some cases, however, it is more convenient to use the methods provided by Views to modify a bound data source. The main benefits are:

  • the grid control immediately reflects the changes made to the data source;

    Depending on the data source type, the grid control may not receive change notifications when you add, delete or modify records using the functionality provided by the data source. If your data source does not support change notification, you need to update the grid control manually if you modify the data source directly (i.e., not using the means provided by Views). Refer to the Refreshing the GridControl document for more information. That topic also gives you an example of implementing a notification functionality for your data source.

  • the same code can be applied to several data source types.

You can also enable end-users to add and delete rows using a Data Navigator, and to add rows using the New Item Row feature. Please refer to the Using Navigators and New Item Row Overview topics for details.

Expanded Adding Rows

To add a new row to a View, you can use the ColumnView.AddNewRow method. This method is only supported for data sources implementing the System.ComponentModel.IBindingList interface. In other cases, you should use the methods provided by your data source to add new rows.

A common scenario when using the ColumnView.AddNewRow method is to add a new row and then let the end-user fill its cell values manually. You can also initialize cell values in code using methods provided by the data source or the ColumnView.SetRowCellValue method.

If the New Item Row is enabled, the ColumnView.AddNewRow method moves focus to the existing New Item Row. Otherwise, the New Item Row is temporarily displayed below all data rows. The Grid control moves focus to this row, allowing an end-user to enter values. The New Item Row is automatically hidden once the new data is accepted or discarded.

For more information on the New Item Row and how to initialize some values of the new row in code, refer to New Item Row Overview.

After the row is accepted, the grid moves it to an appropriate position according to the current grouping and sorting settings. The row can be accepted in a number of ways:

The row can be discarded as follows:

Note that for runtime created data, records must implement the System.ComponentModel.IEditableObject interface to enable rollback.

Identifying New Rows

Rows in a View can be identified by row handles. Once you know the handle of a specific row, you can modify this row with the ColumnView.SetRowCellValue method.

If a new row is not yet accepted, it is focused. Thus, its row handle can be obtained using the ColumnView.FocusedRowHandle property. This property will return the value of the GridControl.NewItemRowHandle constant.

Once the row is accepted and posted to the data source, its index in the data source is equal to BaseView.DataRowCount - 1. A handle to this row can be obtained using the ColumnView.GetRowHandle method.

In specific cases, new rows are focused automatically when they are accepted (for instance, when rows are posted using the End Edit button of the Data Navigator). In these cases, you can use the ColumnView.FocusedRowHandle property to obtain the row handle after the row is accepted.

If you add a row using methods of the bound data source, the new row may not be focused automatically. To ensure that the new row added in this way is always focused, set the GridOptionsNavigation.AutoFocusNewRow property to true.

For rows added using the New Item Row and the ColumnView.AddNewRow method, you can write cell initialization code within a ColumnView.InitNewRow event handler.


The following code shows how to add a new row to a data group. It is assumed that data within a Grid View is grouped against one or more columns. The row is added to the same group as the currently focused row.

First, we obtain the values of the group columns of the currently focused row and store them in an array. Second, a new row is added and its fields that correspond to the group columns are set to the values stored beforehand. Third, the new row is accepted and this rearranges all rows to meet current group settings. Finally, the new row is focused.

Expanded Deleting Rows

To delete a row from a data source, use the ColumnView.DeleteRow method. The method is only in effect for data sources that support record deletion. The row to delete is identified by the row handle passed as a parameter. The ColumnView.DeleteRow method can delete both data and group rows.

If a grid control is bound to a System.Data.DataSet with master-detail relationships set up between tables, then the ColumnView.DeleteRow method deletes the desired row and its associated child rows, if any. Refer to the Master-Detail Overview document for information on the master-detail mode.

If a Data Navigator is enabled, an end-user can delete rows with the Delete button provided by the Data Navigator (the data source must support record deletion).

Expanded Deleting Selected Rows

When a View's ColumnViewOptionsSelection.MultiSelect property is set to true, the grid control enables multiple row or cell selection mode. In Grid Views, it is possible to choose between multiple row and cell selection modes using the GridOptionsSelection.MultiSelectMode property, so that multiple rows or individual cells can be selected simultaneously. The ColumnView.DeleteSelectedRows method allows you to delete selected rows (in multiple row selection mode) or rows that contain selected cells (in multiple cell selection mode). In single row selection mode (when the ColumnViewOptionsSelection.MultiSelect property is set to false), the ColumnView.DeleteSelectedRows method deletes the focused record. In Grid Views, this method also deletes selected group rows.

For additional information on selection modes, see the Multiple Row and Cell Selection document.

Expanded See Also

How would you rate this topic?​​​​​​​