辰凌风

"Forget What Made Them Successful " Trap

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

dataGirdView 默认加载数据后,会选择第一行的第一个可见单元格。而有的时候我们不需要这样,已达到让容易点击一个后,在进行操作。

我们可以用如下的代码实现:

dataGridView1.Rows[0].Selected = false;
this.dataGridView1.TabStop = false;
dataGridView1.Rows[0].Selected = false;
this.dataGridView1.CurrentCell = null;
dataGridView1.ClearSelection();

但是有个注意点:

不能写在窗体的初始化函数里面写。。
只能在 Load里面写。。

public Form1()
{
InitializeComponent();
dataGridView1.Rows[0].Selected = false;//无效
//this.dataGridView1.TabStop = false;//无效
//dataGridView1.Rows[0].Selected = false;//无效
//this.dataGridView1.CurrentCell = null;//无效
//dataGridView1.ClearSelection();//无效
//dataGridView1.Rows[0].Selected = false; //无效
}
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.Rows[0].Selected = false;
//this.dataGridView1.TabStop = false;
//dataGridView1.Rows[0].Selected = false;
//this.dataGridView1.CurrentCell = null;
//dataGridView1.ClearSelection();
}

 

当然也可以放在按钮下,神马的~

posted on 2012-06-15 18:24  辰凌风  阅读(612)  评论(0编辑  收藏  举报
忒客淘-我的站