如何从绑定的DataRow中确定DataGridViewRow(How to determine a DataGridViewRow from the DataRow it is bound to)

编程入门 行业动态 更新时间:2024-10-27 12:24:50
如何从绑定的DataRow中确定DataGridViewRow(How to determine a DataGridViewRow from the DataRow it is bound to)

我想在触发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)).

更多推荐

本文发布于:2023-08-07 03:16:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459744.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   DataRow   DataGridViewRow   determine   bound

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!