一、我做过的尝试
- 最开始,我直接在初始化时也就是“ InitializeComponent();”方法所在的函数里添加 以下代码:
this.dataGridView1.Rows[3].Selected = true; //窗体打开时默认选中第4行(PS:第一行是0)
结果运行时,还是默认选中的第一行,defeat!!!
- 后来上网查了一下,找到最多的解决办法思路是先清除,再选择,代码如下
this.dataGridView1.ClearSelection();
this.dataGridView1.CurrentCell = null;
this.dataGridView1.Rows[3].Selected = true;
运行时,还是默认选中的第一行,defeat!!!
- 再后来,看到一个方案说要在“ Form_Load " 函数里选择,于是:
private void Form1_Load(object sender, EventArgs e)
{
this.dataGridView1.ClearSelection();
this.dataGridView1.CurrentCell = null;
this.dataGridView1.Rows[3].Selected = true;
}
运行时,还是默认选择第一行,defeat!!!
后来又尝试了很多方法(大体思路就是以上三条),都没有成功,后来东拼西凑,看到一个帖子说要把 dataGridView1的TabStop属性设置为false,我就试了一下,结合上面第三条,就可以达到我想要的效果了。
(PS:要想选中整行,dataGridView1的SelectionMode属性设为FullRowSelect)
(又PS:由于查资料时东看一篇西看一篇,而且很多资料给的解答类似,且最终解决方案也是我后来瞎试试出来的(网页早关了),找不到借鉴处了,这里就不附上链接了)