我已经创建了一个 DataGridViews 数组,并为每个 gridview DataGridViewCellEventHandler 添加,我想在单击时更改当前 DataGridView 单元格值,要更改单元格值,您必须从数组中知道当前 DataGridView 索引为 dataGridView[i].Rows [colIndex].Cells[rowIndex].Value,
如何找出点击了哪个DataGridView?
这是我的代码。
DataGridView[] altGridViews=new DataGridView[10];
for (int i = 0; i < 10; i++)
{
altGridViews[i]=new DataGridView();
altGridViews[i].RowCount = 3;
altGridViews[i].ColumnCount = 3;
altGridViews[i].AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
altGridViews[i].CellClick += new
DataGridViewCellEventHandler(altGridView_Click);
this.Controls.Add(altGridViews[i]);
}
和 DataGridView 甚至处理程序
protected void altGridView_Click(object sender, DataGridViewCellEventArgs e)
{
int colIndex = e.ColumnIndex;
int rowIndex = e.RowIndex;
//todo: change current cell value
//altGridViews[i].Rows[colIndex].Cells[rowIndex].Value="something";
}