当 DataGridViewComboBox 的选定索引更改时,如何立即更改行颜色?
我正在使用 Windows 窗体,并且有一个 DataGridView 和绑定到数据源的 DataGridViewComboBoxColumn。
当用户从组合框中选择不同的项目时,我想立即更改行颜色以指示此新选择。
我已经测试了多个事件,例如 CellValueChanged 和 RowPrePaint,但这些事件要求用户在做出选择后单击行外的按钮。
该行似乎不会立即更新。相反,它会在用户单击该行后更新。 (即这是大多数网格的工作方式,但我想改变这种行为并为用户提供即时反馈)
I'm using Windows Forms and have a DataGridView with a DataGridViewComboBoxColumn that is bound to a data source.
When the user chooses a different item from the combo box, I'd like to immediately change the row color to indicate this new selection.
I've tested several events such as CellValueChanged and RowPrePaint, but these requires that the user clicks off the row after making the selection.
It seems like the row doesn't update immediately. Instead, it updates after the user clicks off the row. (i.e. this is how most grids work but I'd like to change this behavior and give the user immediate feedback)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 DataGridView 的 EditingControlShowing 事件并为 ComboBox.SelectedIndexChanged 事件添加事件处理程序:
并在事件处理程序中设置 CurrentRow 的颜色:
You can use the
EditingControlShowing
event of the DataGridView and add an event handler for theComboBox.SelectedIndexChanged
event:and in the event handler, set the color for the
CurrentRow
: