DataGridView / DataTable | rowState doesn't change

懵懂的女人 提交于 2019-12-10 00:50:08

问题


I'm having a problem with binding data to the DataGridView.

I have a class MyDataGridView that inherit from DataGridView. My data grid view data source is a BindingSource object that holds a DataTable as the data source.

Problem is, when I make changes via (my) DataGridView object - the rowState stays on 'unmodified' instead of modified; even though the values in the DataTable changed (that's what makes my update not work, since it consider the rowState as undefined). Notice that making changes directly to the DataTable works fine.

Thank you (:


回答1:


you must call the Validate method of the form that contains the grid. This method affect to grid as if you move the focus to another row in the grid.




回答2:


Ok, so after using google a little bit I found out that calling DataTable.Rows[index].EndEdit() solves the problem. I'm not sure if that's how I should do that but it solved the problem. (in order to call that method I use the DataGridView.CellEndEdit event).




回答3:


Can you show us the MyDataGrdView class code please?

and i think i already know the solution: you have to rebind the data source so the control knows when to update

call DataGridView.DataBind(); evrytime you have changed the data source. it's slightly possible you have to do this with your DataTable too.



来源:https://stackoverflow.com/questions/10570505/datagridview-datatable-rowstate-doesnt-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!