您的位置:首页 > 其它

Datagridview 滚动条...

2010-03-12 13:54 197 查看

界面上有两个DataGridView,其中的一个的水平滚动条滚动时,另外一个的水平滚动条也能够滚动相同的的距离

用scroll事件
private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
dataGridView1.ScrollBars = ScrollBars.Horizontal;
dataGridView2.ScrollBars = ScrollBars.Horizontal;
//设置DataGridView1和DataGridView2的水平滚动条的像数数相同
dataGridView1.HorizontalScrollingOffset = dataGridView2.HorizontalScrollingOffset;
}

Datagridview中的数据很多,加载完数据后滚动条自动到最下边

this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView1.Rows.Count - 1;

DataGridViewRow 添加到 dataGridView1的方法

DataGridViewRow dgvr = new DataGridViewRow();
int y= dataGridView1.Rows.Add(dgvr);

dgvr.Cells[0].Value = "1";
dgvr.Cells[1].Value = "2";
DataGridViewRow dgvr1 = new DataGridViewRow();
foreach (DataGridViewColumn c in dataGridView1.Columns)
{
dgvr1.Cells.Add(c.CellTemplate.Clone() as DataGridViewCell);//给行添加单元格
}
dgvr1.Cells[0].Value = "3";
dgvr1.Cells[1].Value = "4";

int x= dataGridView1.Rows.Add(dgvr1);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: