I want to acces my Player object in my DataGridView.
This is how I’m binging my Players list to DataGridView:
PlayerList = new List<Player>(players);
//Populate Player list heere (...)
DataTable dt = Tools.ToDataTable<Player>(PlayerList);
Grid.DataSource = dt;
And now I want to access my Player object in selected row in Double click event:
private void Grid_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (Grid.SelectedCells == null)
{
return;
}
int row = Grid.SelectedCells[0].RowIndex;
//Here I get that exception from the title
((Player)(Grid.Rows[row].DataBoundItem)).KillPlayer();
}
1 Answer