一、同步滚动
SumTable为表1,CycleTable为表2
两个表都添加Scroll滚动事件
private void SumTable_Scroll(object sender, ScrollEventArgs e)//滚动同步 { CycleTable.FirstDisplayedScrollingRowIndex = SumTable.FirstDisplayedScrollingRowIndex;//行滚动同步 //CycleTable.FirstDisplayedScrollingColumnIndex = SumTable.FirstDisplayedScrollingColumnIndex;//列滚动同步 } private void CycleTable_Scroll(object sender, ScrollEventArgs e)//滚动同步 { SumTable.FirstDisplayedScrollingRowIndex = CycleTable.FirstDisplayedScrollingRowIndex; //SumTable.FirstDisplayedScrollingColumnIndex = CycleTable.FirstDisplayedScrollingColumnIndex;//列滚动同步 }
二、同步选中
两个表都添加CellClick单元格点击事件
private void SumTable_CellClick(object sender, DataGridViewCellEventArgs e) { if (SumTable.SelectedRows.Count != 0 && e.RowIndex >= 0 && e.RowIndex < CycleTable.Rows.Count) { CycleTable.Rows[e.RowIndex].Selected = true; } } private void CycleTable_CellClick(object sender, DataGridViewCellEventArgs e) { if (CycleTable.SelectedRows.Count != 0 && e.RowIndex >= 0 && e.RowIndex < SumTable.Rows.Count) { SumTable.Rows[e.RowIndex].Selected = true; } }
标签:同步,滚动,C#,CycleTable,DataGridView,数据表,Rows,SumTable,RowIndex From: https://www.cnblogs.com/Kirito-Asuna-Yoyi/p/DataGridViewScroll.html