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?
I'm not sure why that would be. The grid commits changes to the data source based on the UpdateMode property, which defaults up updating when the active cell changes or the grid loses focus. Deleting a row in the grid should certainly cause a change in the ActiveCell. So maybe you have changed the UpdateMode property of the grid to some other setting?
Try calling grid.UpdateData and see if that helps.
How are you getting the data row? Are you sure it's the right row?
I have the same symptom of a grid deleting only from the display, but my datasource is from an sp. I'd like to be able to delete from one of the tables in said sp but I'm not sure what the best way would be. My grid's UpdateMode is set to OnRowChangeOrLostFocus.
You should still be able to use my technique above (my datasource is also a sp)...in the appropriate event handler(s), get the index of the row you want to delete, delete from the datagrid at that index, then delete from your datatable at that index (and/or put the logic in that you need to delete from any datatable that you want). It does seem a little odd, but it works.
Note: I created a delete button and put the code in it's event handler...which works for the context of my app and the skill level of my end users.
I'd like to use the grid's functionality of selecting rows, hitting Del on the keyboard, and their prompt. Records are gone from the grid. Now to really delete them.
So I'm in AfterRowsUpdated. How do I access the index of the row(s)? I'd rather access an ID field, but don't know how to get focus of either.
painted8 said:I'd like to use the grid's functionality of selecting rows, hitting Del on the keyboard, and their prompt. Records are gone from the grid. Now to really delete them.
What do you mean by "Now to really delete them?" I assume that this is a typo and that you meant to type "Not" instead of "Now. But I'm still not clear on what you mean. If you are using the grid's functionality to delete rows then the rows will get deleted from the data source.
painted8 said:So I'm in AfterRowsUpdated. How do I access the index of the row(s)? I'd rather access an ID field, but don't know how to get focus of either.
There is no AfterRowsUpdated event that I am aware of. There's an AfterRowUpdate event, but this fires for a single row update, and has nothing to do with the deletion of rows. For deleting, you would use Before/AfterRowsDeleted. The event passes you a list of the rows, I think. Or if not, then you can use the grid.Selected.Rows collection.
Mike,
I am having the same problem--I have an UltraGrid (bound to a DataTable) with a button column for delete, and on the click event I call e.Cell.Row.Delete(false) and the row is removed from the grid.
In my Save function (called from when the user clicks an OK button outside the grid), I call UpdateData on my UltraGrid. The grid shows 1 row, and the DataTable has 2. Granted, the rowstate of one of them is Deleted, but it seems like it should be gone.
Is that correct behavior?Thanks,
J
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,
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