C#dataGridView 滚动条 同步
我想用滚动条同时控制两个datagridview,拉一个滚动条的时候,另外的一个datagridview也相应移动,求大神们帮帮吧......
我想用滚动条同时控制两个datagridview,拉一个滚动条的时候,另外的一个datagridview也相应移动,求大神们帮帮吧...
展开
1个回答
展开全部
private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Columns.Add("col3");
for (int i = 0; i < 100; i++)
{
dt.Rows.Add(new object[] { i,i+1,i+2});
}
this.dataGridView1.DataSource = dt;
this.dataGridView2.DataSource = dt;
}
private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
dataGridView2.FirstDisplayedScrollingRowIndex = dataGridView1.FirstDisplayedScrollingRowIndex;
dataGridView2.HorizontalScrollingOffset = dataGridView1.HorizontalScrollingOffset;
}
private void dataGridView2_Scroll(object sender, ScrollEventArgs e)
{
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView2.FirstDisplayedScrollingRowIndex;
dataGridView1.HorizontalScrollingOffset = dataGridView2.HorizontalScrollingOffset;
}
{
DataTable dt = new DataTable();
dt.Columns.Add("col1");
dt.Columns.Add("col2");
dt.Columns.Add("col3");
for (int i = 0; i < 100; i++)
{
dt.Rows.Add(new object[] { i,i+1,i+2});
}
this.dataGridView1.DataSource = dt;
this.dataGridView2.DataSource = dt;
}
private void dataGridView1_Scroll(object sender, ScrollEventArgs e)
{
dataGridView2.FirstDisplayedScrollingRowIndex = dataGridView1.FirstDisplayedScrollingRowIndex;
dataGridView2.HorizontalScrollingOffset = dataGridView1.HorizontalScrollingOffset;
}
private void dataGridView2_Scroll(object sender, ScrollEventArgs e)
{
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView2.FirstDisplayedScrollingRowIndex;
dataGridView1.HorizontalScrollingOffset = dataGridView2.HorizontalScrollingOffset;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询