我的“玩家”有DataGridView和DataTable。
DataTable dt = Extensions.ToDataTable<Player>(PlayerList);
Grid.DataSource = dt;
当用户点击网格中的任何单元格时,我想在doubleclick事件中访问Player objet。 怎么做?
答案 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;
}