Home › Forums › WinForms controls › Xceed Grid for WinForms › Deleting a record
-
AuthorPosts
-
#16935 |
How can I delete a record from master view which is bounded one the record should be deleted in the database also and how can I select a particular record to be deleted
Imported from legacy forums. Posted by yeswanth (had 3949 views)
To remove a row from the grid, you need to identify which row, or get a reference of the row in question, and remove it from the DataRows collection.
e.g. :
//you can also use RemoveAt() if you know the index of the row.
gridControl1.DataRows.Remove( ( Xceed.Grid.DataRow )gridControl1.CurrentRow );This will also remove the row from the DataSet to which the grid is bound, through the CurrencyManager, which synchronizes both the grid and the DataSet together.
However to remove the same row from the DB, you need to update the DB through the data adapter that you use to fill the DataSet, and to accept the changes on the DataSet. When filling the DataSet, the Fill() method is used; when updating the DB from the DataSet, the Update() method is used.
e.g.:
this.suppliersTableAdapter.Update( this.northwindDataSet.Suppliers );
this.northwindDataSet.Suppliers.AcceptChanges();I suggest you read a bit on Data binding in .NET to learn how to do this. Here is a few links that should get you started :
http://msdn.microsoft.com/en-us/library/h43ks021(VS.71).aspx
http://msdn.microsoft.com/en-us/library/s7ee2dwt(VS.71).aspx
http://msdn.microsoft.com/en-us/library/ss7fbaez(VS.71).aspxImported from legacy forums. Posted by André (had 3636 views)
Hi,
Inorder to remove a row from the grid we need to know the row index ,getting that row index is the problem .I have inserted the checkbox for every row
if I clicked the checkbox I need to get the rowindex.inorder to remove the row.So please let me know how to get to that.
Imported from legacy forums. Posted by yeswanth (had 341 views)
If you want to remove the currentRow :
myGrid.CurrentRow.Remove()
If you want to remove all selected rows :
For Each rows As Xceed.Grid.DataRow In myGrid.DataRows
If rows.Cells(“delete_checkbox”).Value Then rows.Remove()
NextAnd don’t forget to apply the changes to the database!
Imported from legacy forums. Posted by Daniel (had 459 views)
Hi,
How can i update my database its not working with acceptchanges
Imported from legacy forums. Posted by yeswanth (had 504 views)
Can you specify what you mean by “not working”? Do you get an exception? If so, can you paste the exception message and stack trace? Can you also provide the code snippet you use to update the DB?
Imported from legacy forums. Posted by André (had 3520 views)
Hi,
I have set checkboxes for each datarow for suppose I have four rows if I clicked on second one and pressing of delete that particular show should be deleted.In order to delete like that I have to get the index value of that row .So please let me know the code.
Imported from legacy forums. Posted by yeswanth (had 576 views)
You can use the Index property to get the index of a row, and you can use a loop to verify which rows have the CheckBox in the right status, as shown by Daniel. Or you can use the CurrentRow property to get the index of the row that is being selected.
e.g.:
int rowIndex = ( ( Xceed.Grid.DataRow )gridControl1.CurrentRow ).Index;
However, if you remove a row you have selected by using the Remove() method on the row, you don’t need the index. The row is already removed from the DataSet. What is left is to call Update() on the DataAdapter and call AcceptChanges() on the DataSet, as I have shown in a previous post.
e.g.:
this.suppliersTableAdapter.Update( this.northwindDataSet.Suppliers );
this.northwindDataSet.Suppliers.AcceptChanges();If this does not resolve the issue, I will need a better explanation of what you want to do, and a code snippet of what you are doing, and what is not working (detailing how it is not working, with exception details if applicable).
Imported from legacy forums. Posted by André (had 3535 views)
Hi,
How can i delete multiple datarows at a time by selecting 2/3 rows and clicking on delete that should be deleted in the database also.Please give me the code
Imported from legacy forums. Posted by yeswanth (had 465 views)
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)
-
AuthorPosts
- You must be logged in to reply to this topic.