您的位置:首页 > 编程语言 > C#

c# DataGridView时如何让滚动条定位到用户选择的行?

2010-10-08 09:13 781 查看
首先在单击单元格时获得当前行的索引  
      int index;//当前行索引
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            index = this.dataGridView1.CurrentRow.Index;
        }

然后在你刷新数据的方法中调用以下,就可实现定位
this.dataGridView1.DataSource = ds.Tables[0];
dataGridView1.Rows[index].Selected = true;        
this.dataGridView1.FirstDisplayedScrollingRowIndex = index;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  c# object