我想在触发DataTable事件时更改DataGridViewRow的前景色(特别是DataColumnChangeEvent )。 为此,我需要获取事件发生的行的关联DataGridViewRow 。
我有以下内容:
private void DataColumnChanged(object sender, DataColumnChangeEventArgs e) { DataColumn col = e.Column; DataRow row = e.Row; if (col != null && row != null) { if (col.ColumnName == "abc") { String str = col.ToString(); if (str == "1") { DataGridViewRow dgvr = <somehow get row's associated DataGridViewRow> ChangeRowForeColor(dgvr, "Purple"); } } }以下问题是相反的方向(从DataGridViewRow获取DataRow ),所以我知道它至少可以找到一种方式,但我似乎无法找到有关反向问题的信息。
如何从DataGridView中的行获取DataRow
如何确定哪个DataRow绑定到DataGridViewRow
将非常感谢如何从DataRow确定DataGridViewRow示例代码。
I would like to change the forecolor of a DataGridViewRow when a DataTable event is fired (specifically the DataColumnChangeEvent). In order to do so I need to get the associated DataGridViewRow of the row the event occurred on.
I have the following:
private void DataColumnChanged(object sender, DataColumnChangeEventArgs e) { DataColumn col = e.Column; DataRow row = e.Row; if (col != null && row != null) { if (col.ColumnName == "abc") { String str = col.ToString(); if (str == "1") { DataGridViewRow dgvr = <somehow get row's associated DataGridViewRow> ChangeRowForeColor(dgvr, "Purple"); } } }The following questions are the reverse direction (getting a DataRow from a DataGridViewRow), so I know that it can be found one way at least, but I can't seem to find info on the reverse problem.
How do I get a DataRow from a row in a DataGridView
How to determine which DataRow is bound to a DataGridViewRow
Example code of how to determine a DataGridViewRow from a DataRow would be greatly appreciated.
最满意答案
在行的主键上调用dataView.Find 。
编辑 :要查找DataRowView的DataGridViewRow ,请调用grid.Rows[dataView.IndexOf(drv)) 。
Call dataView.Find on the row's primary key.
EDIT: To find the DataGridViewRow for a DataRowView, call grid.Rows[dataView.IndexOf(drv)).
更多推荐
发布评论