I have this datagridView that takes data from an object. I add columns like this:
dataGridView1.CellClick += dataGridView1_CellClick;
DataGridViewButtonColumn colUsers = new DataGridViewButtonColumn();
colUsers.UseColumnTextForButtonValue = true;
colUsers.Text = "Users";
colUsers.Name = "";
dataGridView1.Columns.Add(colUsers);
And I add an onclick event, but it's not working, am I missing something?
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.RowIndex > -1 && dataGridView1.Columns[e.ColumnIndex].Name == "Users")
{
name = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
gtUserDetails.ShowDialog();
}
}
I get an error: Index was out of range. Must be non-negative and less than the size of the collection.