【问题标题】:Scroll a datagridview from a different scroll bar?从不同的滚动条滚动数据网格视图?
【发布时间】:2014-12-19 07:49:39
【问题描述】:

我有一个 datagridview 我想从一个单独的水平滚动条滚动它。 IE。当我移动这个栏时,它会滚动 datagridview。

这是我目前所拥有的:

Private Sub HScrollBar1_Scroll(sender As Object, e As ScrollEventArgs) Handles HScrollBar1.Scroll
    cameraTable.HorizontalScrollingOffset = e.NewValue
End Sub

虽然 datagridview 不滚动。有什么建议么?

【问题讨论】:

  • 发现问题:datagridview 没有足够的列来滚动。

标签: vb.net winforms datagridview


【解决方案1】:

使用DataGridView.CurrentCellDataGridView.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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    相关资源
    最近更新 更多