Articles in this section
Category / Section

How to add a new row in the Grid?

1 min read

To add rows or columns to the GridDataBoundGrid control, you have to add columns or rows to the DataSource, that is mapped to the GDBC control. Use the AcceptChanges() property to accept all changes in the DataSource when the rows or columns added.

The following code example demonstrates the same.

C#

void GridDataBoundGrid1_CellClick(object sender, Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs e)
{
 if (e.MouseEventArgs.Button == MouseButtons.Right)
 {
  DataRow tableRow = table.NewRow();
  table.Rows.InsertAt(tableRow, e.RowIndex); //Adds the row.
  // table.Columns.Add(); //Adds the column.
  table.AcceptChanges();   
  this.GridDataBoundGrid1.Refresh();
 }
}

 

VB

Private Sub GridDataBoundGrid1_CellClick(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.GridCellClickEventArgs)
 If e.MouseEventArgs.Button = MouseButtons.Right Then
  Dim tableRow As DataRow = table.NewRow()
  table.Rows.InsertAt(tableRow, e.RowIndex) 'Adds the row.
  'table.Columns.Add(); //Adds the column.
  table.AcceptChanges()
  Me.GridDataBoundGrid1.Refresh()
 End If
End Sub

 

Note:

The same procedure can be used for the Gridcontrol and GridGroupingcontrol.

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied