【发布时间】:2012-01-06 18:13:38
【问题描述】:
我想在双击单元格时更改 datagridview 中单元格的颜色。我添加了一个 CellDoubleClick 处理程序,该处理程序在双击单元格后正确触发:
Private Sub myDataGridView_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles myDataGridView.CellDoubleClick
myDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.ForeColor = Color.Red
myDataGridView.Refresh() 'I added this to try to fix the problem
Application.DoEvents() 'I added this to try to fix the problem
end sub
但在事件“触发”后,UI 不会立即更改单元格文本的颜色。相反,如果我单击一个 不同 单元格,那么 Visual Studio 2010 会将 original 单元格更改为红色(就像处理程序所说的那样)。
似乎每次单击不同的单元格时都会进行某种 UI 刷新/UI 重绘。这个对吗?有没有办法以编程方式刷新 UI。许多 stackoverflow 帖子建议 .refresh 但这不起作用。
【问题讨论】:
标签: .net winforms datagridview