我有一个datagridview,我想从一个单独的水平滚动条滚动它。即当我移动这个栏时,它会用它滚动datagridview。
这是我到目前为止所拥有的:
Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollBar1.Scroll
cameraTable.HorizontalScrollingOffset = e.NewValue
End Sub
datagridview不会滚动。有什么建议?
答案 0 :(得分:0)
使用DataGridView.CurrentCell
或DataGridView.FirstDisplayedCell
属性滚动显示。
Option Strict On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
'Fill grid with dummy data
Dim dtb As New DataTable("MyDataTable")
For i As Integer = 0 To 99
dtb.Columns.Add("C" & i.ToString)
Next i
For j As Integer = 0 To 99
Dim s(99) As String
For i As Integer = 0 To 99
s(i) = ((i + j) Mod 100).ToString
Next i
dtb.Rows.Add(s)
Next j
DataGridView1.DataSource = dtb
End Sub
Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollBar1.Scroll
'Use the DataGridView.FirstDisplayedCell property to scroll the display
DataGridView1.FirstDisplayedCell = DataGridView1.Rows(DataGridView1.CurrentCell.RowIndex).Cells(e.NewValue)
End Sub
End Class