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.
Call
dataView.Findon the row’s primary key.EDIT: To find the
DataGridViewRowfor aDataRowView, callgrid.Rows[dataView.IndexOf(drv)).