Trying to use the following code to pull a value from a datagridview cell:
The problem is that that loading the dgv triggers a selection change. So, when I load the grid, I get an ArgumentOutOfRangeException. My weird workaround is the following:
Although it works, it seems a little wonky. Suggestions to make it cleaner?
C#:
private void dgvSQL_SelectionChanged(object sender, EventArgs e)
{
txtBoxMatchType.Text = dgvSQL.SelectedRows[0].Cells[0].Value.ToString();
}
The problem is that that loading the dgv triggers a selection change. So, when I load the grid, I get an ArgumentOutOfRangeException. My weird workaround is the following:
C#:
private void dgvSQL_SelectionChanged(object sender, EventArgs e)
{
try
{
txtBoxMatchType.Text = dgvSQL.SelectedRows[0].Cells[0].Value.ToString();
}
catch (Exception ex)
{
//Do nothing
}
}
Although it works, it seems a little wonky. Suggestions to make it cleaner?