I have a column fields with different names. For example I load the files from ABC. and the Name column fields will be ABC.
I have to show a button only when I select the ABC row object.
I wrote a code below, but its throwing an exception. It would be great helpful if someone suggest me on this.
FormViewButton fvb = FormViewButton.getInstance();
foreach (DataGridViewRow row in this.dataGridView1.Rows)
{
row.DefaultCellStyle.SelectionBackColor = this.dataGridView1.DefaultCellStyle.SelectionBackColor;
bool selectedRow = row.Cells["Name"].Selected;
if (row.Cells["Name"].Value.ToString().Equals("ABC") && selectedRow == true) // A Nullreferenceexception was unhandled by user code is thrown here.
{
fmv.showButton.Visible = true;
}
else if (!row.Cells["Name"].Value.ToString().Equals("ABC") && selectedRow != true)
{
fmv.showButton.Visible = false;
}
}