DataGridView和DataTable

时间:2012-01-01 22:21:34

标签: c# .net datagridview datatable

我的“玩家”有DataGridView和DataTable。

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

当用户点击网格中的任何单元格时,我想在doubleclick事件中访问Player objet。 怎么做?

1 个答案:

答案 0 :(得分:3)

为DataGridView的CellContentDoubleClick事件添加处理程序,然后访问该行的DataBoundItem:

DataGridView1.CellContentDoubleClick += DataGridView1_CellContentDoubleClick;

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