datagrid doesn't save the data
-
I set up the datasource myDataGrid.DataSource= myDataSet.Tables[0].DefaultView; When I scroll the cursor to next row, datagrid updates the dataset. It's ok. But without doing it, datagrid doesn't update the dataset. myDataSet.Tables[0].Rows.Count is 0 and myDataSet.Tables[0].DefaultView.Count is 1. For example user can enter some data to datagrid then after closes the window. Datagrid doesn't affect the dataset row. I need to say "save data" to datagrid. How can I do this? Thanks
-
I set up the datasource myDataGrid.DataSource= myDataSet.Tables[0].DefaultView; When I scroll the cursor to next row, datagrid updates the dataset. It's ok. But without doing it, datagrid doesn't update the dataset. myDataSet.Tables[0].Rows.Count is 0 and myDataSet.Tables[0].DefaultView.Count is 1. For example user can enter some data to datagrid then after closes the window. Datagrid doesn't affect the dataset row. I need to say "save data" to datagrid. How can I do this? Thanks
-
Try to accept the changes in your datasource. ((DataSet)(myDataGrid.DataSource)).AcceptChanges(); or simply DataSet1.AcceptChanges(); Anfernius
It doesn't work. Because data is in the datagrid. Datagrid has to send the data to dataset Thanks for your interest.
-
Try to accept the changes in your datasource. ((DataSet)(myDataGrid.DataSource)).AcceptChanges(); or simply DataSet1.AcceptChanges(); Anfernius
All that does is mark the rows as unchanged so that if you passed the
DataSet
toDataAdapter.Update
, no rows would be updated in your database (or other data store).Microsoft MVP, Visual C# My Articles
-
I set up the datasource myDataGrid.DataSource= myDataSet.Tables[0].DefaultView; When I scroll the cursor to next row, datagrid updates the dataset. It's ok. But without doing it, datagrid doesn't update the dataset. myDataSet.Tables[0].Rows.Count is 0 and myDataSet.Tables[0].DefaultView.Count is 1. For example user can enter some data to datagrid then after closes the window. Datagrid doesn't affect the dataset row. I need to say "save data" to datagrid. How can I do this? Thanks
This is just the way the
DataGrid
works (as well as other controls). The changes aren't commited until the control looses focus. For a little bit more understanding, see theDataGridColumnStyle.Commit
method documentation in the .NET Framework SDK. If you want to force the text (or whatever) to be commited, then you could, for example, callDataGrid.EndEdit
before yourForm
closing (like overriding theOnClosing
method or handling theClosing
event). See that method documentation in the .NET Framework SDK for more information.Microsoft MVP, Visual C# My Articles
-
This is just the way the
DataGrid
works (as well as other controls). The changes aren't commited until the control looses focus. For a little bit more understanding, see theDataGridColumnStyle.Commit
method documentation in the .NET Framework SDK. If you want to force the text (or whatever) to be commited, then you could, for example, callDataGrid.EndEdit
before yourForm
closing (like overriding theOnClosing
method or handling theClosing
event). See that method documentation in the .NET Framework SDK for more information.Microsoft MVP, Visual C# My Articles
thanks. EndEdit works fine.