Hooch
Hooch

Reputation: 29673

DataGridView and DataTable

I have DataGridView and DataTable with my "players".

        DataTable dt = Extensions.ToDataTable<Player>(PlayerList);
        Grid.DataSource = dt;

I want to access Player objet in doubleclick event when user clicks any cell in my grid. How to do it?

Upvotes: 0

Views: 749

Answers (1)

competent_tech
competent_tech

Reputation: 44921

Add a handler for the CellContentDoubleClick event of the DataGridView, then access the DataBoundItem of the row:

DataGridView1.CellContentDoubleClick += DataGridView1_CellContentDoubleClick;

private void DataGridView1_CellContentDoubleClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
{
   Player player = DataGridView1.Rows[e.RowIndex].DataBoundItem as Player;
}

Upvotes: 3

Related Questions