设置滚动条的Max值、SmallChange/LargeChange值,写Scroll事件了。
水平和垂直都一样。
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.ScrollBars = ScrollBars.None;//关datagridviwe自带滚动条
vScrollBar1.Maximum = dataGridView1.Rows.Count - 1;
vScrollBar1.SmallChange = 1;
vScrollBar1.LargeChange = 1; //Large随便了,我都设定的是1
hScrollBar1.Maximum = dataGridView1.ColumnCount - 1;
hScrollBar1.SmallChange = 1;
hScrollBar1.LargeChange = 1; //Large随便了,我都设定的是1
}
给水平和垂直加Scroll事件
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
dataGridView1.FirstDisplayedScrollingRowIndex = e.NewValue;
}
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
dataGridView1.FirstDisplayedScrollingColumnIndex = e.NewValue;
}