C#怎么让DatagridView一启动就让鼠标点击第一个单元格

2025-01-07 04:41:18
推荐回答(2个)
回答1:

你是想让DatagridView第一行获得焦点还是想执行dataGridView1_CellClick事件
//DatagridView第一行获得焦点
private void button1_Click(object sender, EventArgs e)
{
dataGridView1[0, 0].Selected = true;
}

//执行dataGridView1_CellClick事件
private void button1_Click(object sender, EventArgs e)
{
DataGridViewCellEventArgs dataGridViewCellEventArgs = new DataGridViewCellEventArgs(0, 0);
dataGridView1_CellClick(dataGridView1, dataGridViewCellEventArgs);
}
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
MessageBox.Show("列:" + e.ColumnIndex + "\n" + "行:" + e.RowIndex);
}

回答2:

据我所知,只要你选择了selectfullrows这一项,近件在启动以后就会自动选中第一个单元格