DataGridView and DataTable
本文关键字:DataTable and DataGridView | 更新日期: 2023-09-27 18:19:16
我有DataGridView和DataTable与我的"players"。
DataTable dt = Extensions.ToDataTable<Player>(PlayerList);
Grid.DataSource = dt;
我想访问播放器对象在双击事件时,用户单击任何单元格在我的网格。怎么做呢?
为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;
}