Home Forums WinForms controls Xceed Grid for WinForms Deleting a record Reply To: Deleting a record

User (Old forums)
Member
Post count: 23064

Here is one way of doing it, assuming a binding to the Northwind DB on the Order Details table, and a button used to delete the selected rows in the grid.

e.g.:

    private void Form1_Load( object sender, EventArgs e )
    {
      gridControl1.SetDataBinding( this.orderDetailsBindingSource, “” );

      this.order_DetailsTableAdapter.Fill( this.northwindDataSet.Order_Details );

    }

    private void button1_Click( object sender, EventArgs e )
    {
      //remove the selected rows from the DataRows collection
      int index = gridControl1.SelectedRows.Count;
      for( int i = 0; i < index; i++ )
      {
        Row row = gridControl1.SelectedRows[ 0 ];
        row.Remove();
      }

      //update the database
      this.order_DetailsTableAdapter.Update( this.northwindDataSet.Order_Details );
      this.northwindDataSet.Order_Details.AcceptChanges();
    }
 

 

Imported from legacy forums. Posted by André (had 4296 views)