How to define a DataGridViewRow from a DataRow, it is associated with

I want to change the forecolor of a DataGridViewRow on a DataTable event (in particular, DataColumnChangeEvent ). To do this, I need to get the associated DataGridViewRow row in which the event occurred.

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 associated DataGridViewRow> ChangeRowForeColor(dgvr, "Purple"); } } } 

The following questions relate to the opposite direction (getting a DataRow from a DataGridViewRow ), so I know that it can be found in at least one way, but I cannot find information about the opposite problem.

How to get a DataRow from a row in a DataGridView

How to determine which DataRow is bound to a DataGridViewRow

It would be very helpful to evaluate the code on how to determine a DataGridViewRow from a DataRow .

+4
source share
1 answer

Call dataView.Find in the primary key of the row.

EDIT . To find a DataGridViewRow for a DataRowView , call grid.Rows[dataView.IndexOf(drv)) .

+4
source

Source: https://habr.com/ru/post/1369059/


All Articles