AcceptChanges on DataTable reverts cell styles
I have a DataGridView with a BindingSource as it's data source and a DataTab开发者_运维知识库le as BindingSource's data source. When I load data and my grid, I set up style on some cells by calling:
grid.Rows[0].Cells[0].Style.BackColor = Color.Red;
My BindingSource has some logic on CurrentChanged event. When the current row changes at the end of this logic I call AcceptChanges on my DataTable. Unfortunately this causes cell style of this row's cells beeing reverted to the original state.
How to force grid not to revert cell styles on DataTable.AcceptChanges? Maybe I'm doing something wrong.
Does the color of cell depend on some attributes or columns of the datatable bound?
I guess when you call AcceptChanges it causes the DataGridView to redraw as its underlying datasource has changed.
What I'd try is using RowDataBound
or CellFormatting
event and change the color (of the column in corresponding row) in the handler.
精彩评论