[Expand]General Information
[Collapse]WinForms Controls
  .NET Core Support
 [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]Get Started With Data Grid and Views
   [Expand]Data Binding
    Unbound Columns
   [Collapse]Data Editing and Validation
    [Expand]ErrorInfo Support
     Add and Remove Rows
     Cell Values, Editors, and Validation
   [Expand]Filter and Search
   [Expand]Focus and Selection Handling
    Format Cell Values
   [Expand]Master-Detail Relationships
   [Expand]Asynchronous Image Load
   [Expand]Export and Printing
   [Expand]Appearance and Conditional Formatting
    Split Presentation
    Row Preview Sections
   [Expand]Batch Modifications
    Hit Information
    Popup Menus
   [Expand]Save and Restore Layout
   [Expand]Visual Elements
   [Expand]Design-Time Features
   [Expand]End-User Capabilities
    Included Components
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Gantt Control
  [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]Sunburst Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Add and Remove Rows

Expanded Common Requirements

You and your end-users can add and remove Data Grid rows only if its underlying data source allows for such an action. For example, the ExcelDataSource is a read-only data source; thus, data editing in a grid bound to this source is not available. Similarly, if a Data Grid is bound to a data source that implements the System.ComponentModel.IBindingList interface, the row operations' availability depends on boolean IBindingList.AllowNew and IBindingList.AllowRemove settings. Note that Lists with simple type objects (e.g., List<string>) are not supported - instead, you need to create a class with one property of this required simple type. This class must have an empty default constructor.

Expanded New Item Row

The Data Grid can display an empty row that end-users utilize to add new records. This row is identified by an asterisk (*) displayed within a corresponding row indicator cell. To cancel adding a new row, press Esc.

Demos: Table View | Use New Item Row to add rows

Related API

Expanded Initialize New Rows

The ColumnView.InitNewRow event fires whenever a new record is being added by an end-user. Handle this event to facilitate user input and initialize new rows with required starting cell values.

In the Init newly added rows in a custom manner demo module every new row automatically receieves starting values for cells under "Record Date", "Name" and "Notes" columns.

Expanded Data Navigator

The Data Navigator is an embedded toolbar that allows end-users to navigate through Data Grid records and add/remove rows.

Related API

Expanded External Control Navigator

The Data Navigator is a ControlNavigator object displayed directly within a Data Grid. If needed, you can create a standalone Control Navigator and position it anywhere outside your Grid. Utilize the navigator's ControlNavigator.NavigatableControl property to bind the navigator to a Data Grid. The Control Navigator can also navigate through records of the Tree List and Vertical Grid controls.

Expanded Add and Remove Rows in Code

  • Modifying the underlying data source

    If your data source supports adding and removing records, you can use a data source API to modify Grid rows. If a data source does not implement the System.ComponentModel.IBindingList interface, it does not send add/remove notifications to a Data Grid. In this case, you need to update the Data Grid manually by calling the GridControl.RefreshDataSource (updates main Grid view) or BaseView.RefreshData (updates this particular view) methods. The GridOptionsNavigation.AutoFocusNewRow property allows the Data Grid to automatically focus new records added to a data source. The code below adds a new record to a BindingList object that serves as a data source for a Data Grid. Since this data source supports update notifications, you don't need to refresh the Data Grid manually.

  • ColumnView.AddNewRow

    Adds a blank row to the Data Grid. If the New Item Row is enabled, this method moves focus to this element. Otherwise, the new record is temporarily placed below the existing records. After an end-user has entered cell values and the row has been accepted, the new row moves to its final location according to the current Data Group filtering, grouping and sorting settings. To accept a new row manually, call the ColumnView.UpdateCurrentRow method from code. 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.

  • ColumnView.DeleteRow

    Removes a data record or a group row from the View. If a data source contains multiple tables with master-detail relationships, this method removes a row together with its associated child rows. The code snippet below illustrates how to remove a currently focused row when end-users press the Ctrl+Del shortcut.

  • ColumnView.DeleteSelectedRows

    If the ColumnViewOptionsSelection.MultiSelect property is enabled, end-users can select multiple Data Grid rows (or row cells, depending on the current GridOptionsSelection.MultiSelectMode setting). The DeleteSelectedRows method removes all selected rows and all rows with selected cells if individual cell selection is enabled.

Demos: Remove rows with the Ctrl+Delete shortcut | Prevent a row from being deleted

Is this topic helpful?​​​​​​​