winform datagridview 设置当前活动的单元格

用途:可以动态的设置某一个单元格为已激活的单元格,这样可以达到定位的效果。

 

比如:我要单击某一按钮,使150行第2列的单元格处于激活的状态。

代码如下:

 

View Code
1   private void btnShow_Click(object sender, EventArgs e)
2         {
3             dataGridView1.CurrentCell = dataGridView1[2150];
4            
5         }

 2.如何在datagridview中导航,使当前活动行向下移动。

 

 代码如下:

CurrentCell
 1   private void btnMoveRow_Click(object sender, EventArgs e)
 2         {
 3             int row = dataGridView1.CurrentRow.Index + 1;
 4             if (row>=dataGridView1.RowCount)
 5             {
 6                 row = 0;
 7             }
 8 
 9  
10             dataGridView1.CurrentCell = dataGridView1[0, row];
11             dataGridView1.CurrentRow.Selected = true;
12         }

 

 

 

 

posted on 2011-09-05 10:52  wtq  阅读(1392)  评论(0编辑  收藏  举报