I'm not understand why I'm "periodically" get an Index out of range exception. I can't reproduce but here's the code:
</code>
private void Form1_Load(object sender, EventArgs e)
{
DataGridViewButtonColumn btnShow = new DataGridViewButtonColumn();
dgvDisplay.Columns.Add(btnShow);
btnShow.HeaderText = "Show";
btnShow.Name = "btnShow";
btnShow.Text = "SHOW";
btnShow.UseColumnTextForButtonValue = true;
dgvDisplay.Columns.Add("ID", "Id");
dgvDisplay.Columns.Add("PERSON", "Person");
dgvDisplay.Rows.Add("","123", "John Doe");
dgvDisplay.Rows.Add("","456", "Jane Doe");
}
private void dgvDisplay_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
string s = (string)dgvDisplay.Rows[e.RowIndex].Cells[1].Value;
MessageBox.Show(s);
}
}
<code>
So basically when I click the button I'm retrieving the ID result and displaying it a MsgBox. But periodically I throw an Index out of Range exception.