I have an ultragrid, it is bound to a bindingsource, this binding source is created by BindingSource= new bindingsource(dataset, "TableName"), and then datagrid.datasource=BindingSource.
When I delete one row in the datagrid, that is is disappeared, but in the dataset, that record is still existed in the datatable, and the RowState is "unchanged".
so the record is deleted from datagrid, but not deleted from datasource.
who can help me with this?
EddieMu said:My grid is bound to a BindingNavigator control.
I've never used the BindingNaviagator. But my understanding of it is that it provides the user with a way to control the current position of the data source. So it doesn't seem to make any sense to bind the grid to a BindingNavigator. The proper way to do it would be to bind the grid to a data source and also to bind the BindingNavigator to the same data source. Maybe I am wrong about what the BindingNaviagator does.
Anyway, I doubt that any of that has anything to do with the problem you are having.
When you delete a row from the grid, it sends a notification to the BindingManager to delete the row. How the data source handles that has nothing to do with the grid - it's completely up to the data source.
In the case of a DataSet/DataTable, I am pretty sure that they do not actually delete the row from the table, but rather they simply mark it as in a deleted state. This is so when you propagate your changes back to the back end (the DataBase), you will have information about which rows need to be deleted.
Calling AcceptChanges on the DataSet/DataTable informs it that the changes have been propagated to the back end and it no longer needs to keep them around on the client side.
So if the row is not showing up in the grid after you delete it, that's a pretty clear indication that the grid or the BindingNavigator is working correctly and that the data source knows the row was deleted so it's not revealing it to the BindingManager any more. The fact that the row still exists in the DataSet/DataTable at that point has nothing to do with the grid or the BindingNavigator, and is most likely correct behavior.
If you need to know that the row is in a deleted state, then you should check the State information or refer to the documentation on the DataSet or DataTable class from Microsoft.
EddieMu said: My grid is bound to a BindingNavigator control. This is linked to a binding source that is bound to a dataset object. Clicking on the Delete button on the BindingNavigatorcontrol does remove the row from the grid but does not remove the record from the underlying data table. I added a DataTable.AccpetChanges() command in the AfterRowsDeleted event of the grid but no luck. Any ideas?
My grid is bound to a BindingNavigator control. This is linked to a binding source that is bound to a dataset object. Clicking on the Delete button on the BindingNavigatorcontrol does remove the row from the grid but does not remove the record from the underlying data table.
I added a DataTable.AccpetChanges() command in the AfterRowsDeleted event of the grid but no luck.
Any ideas?
Sorry, I have no experience with BindingNavigator stuff. If you saving row by row and not using a DataAdapter, you will be iterating through the rows in the DataTable that you're saving, and you can check the RowState of the row to see if it's deleted or whatever. That's all I can think of.
Good luck,
J
EddieMu said: I have t he same problem and your proposed solution doesn't work for me. Where are you putting this .AcceptChanges call?
I have t he same problem and your proposed solution doesn't work for me. Where are you putting this .AcceptChanges call?
At the beginning of my Save function. So here's an example of how it looks:
1. DataTable is loaded as grid DataSource--DataTable has 3 rows, grid has 3 rows.
2. User deletes 2 rows out of grid; the grid has 1 row, the DataTable still has 3 (2 of which are in RowState.Deleted).
3. User clicks Save & Exit button. In my Save() function, at the beginning, the DataTable still has 3 rows. I call AcceptChanges on it immediately, and now it has 1 row.
I hope this works for you, it's been a while since I looked at this.
--J