Programatic Edit of a DataGridView
-
Hi, If a user edits a value on a DataGridView, the DataTable under its DataSource recognizes the change when calling DataTable.GetChanges() However, if I edit a value programatically on the DataGridView, the DataTable.GetChanges() returns a NullReferenceException as if no change took place. I know it saved to the DataTable, because I can look at it and see the updated value. Is there something else I need to call on the DataGridView after programatically updating it to make the changes noticable on the DataTable? Some type of commit method that is automatically called when a user edits? Right now I am bypassing the error by updating directly on the DataTable, but I know the DataGridView.Rows is a much smaller collection to loop for changing than the DataTable.Rows (due to filtering already in place). Should I worry about this efficiency issue at all? Thanks, Pualee
-
Hi, If a user edits a value on a DataGridView, the DataTable under its DataSource recognizes the change when calling DataTable.GetChanges() However, if I edit a value programatically on the DataGridView, the DataTable.GetChanges() returns a NullReferenceException as if no change took place. I know it saved to the DataTable, because I can look at it and see the updated value. Is there something else I need to call on the DataGridView after programatically updating it to make the changes noticable on the DataTable? Some type of commit method that is automatically called when a user edits? Right now I am bypassing the error by updating directly on the DataTable, but I know the DataGridView.Rows is a much smaller collection to loop for changing than the DataTable.Rows (due to filtering already in place). Should I worry about this efficiency issue at all? Thanks, Pualee
The datagridview exists solely for the user's benefit. If you want to programatically modify a data set, modify it in memory - your DataTable directly. That is the correct approach.
-
The datagridview exists solely for the user's benefit. If you want to programatically modify a data set, modify it in memory - your DataTable directly. That is the correct approach.