Visual Basic 2010,.NET 3.5 有没有办法实际确定DataGridView的水平滚动条是活动还是可见?当DGV的水平滚动条出现时,我需要移动一些项目。
答案 0 :(得分:5)
试试这个:
dgvYourDataGridView.Controls.OfType(Of HScrollBar).SingleOrDefault.Visible
答案 1 :(得分:3)
只是为了给你一个想法(我现在没时间,或者在我面前的视觉工作室):
For Each c In DataGridView1.Controls
If c.GetType() Is GetType(VScrollBar) Then
Dim vbar as VScrollBar= DirectCast(c, VScrollBar)
If vbar.Visible = True Then
'Do whatever you like
End If
End If
Next
答案 2 :(得分:2)
以下是滚动条可见性更改时从How to detect the vertical scrollbar in a DataGridView control
引发事件的VB.Net版本Public Class MyGrid
Inherits DataGridView
Public Event ScrollbarVisibleChanged As EventHandler
Public Sub New()
AddHandler Me.HorizontalScrollBar.VisibleChanged, _
AddressOf HorizontalScrollBar_VisibleChanged
End Sub
Public ReadOnly Property HorizontalScrollbarVisible() As Boolean
Get
Return HorizontalScrollBar.Visible
End Get
End Property
Private Sub HorizontalScrollBar_VisibleChanged(sender As Object, e As EventArgs)
RaiseEvent ScrollbarVisibleChanged(Me, EventArgs.Empty)
End Sub
End Class
答案 3 :(得分:2)
我拿了Nianios示例,进行了一些调整,然后确定滚动条是否可见。谢谢!
Private Function HScrollBarVisible() As Boolean
Dim ctrl As New Control
For Each ctrl In DataGridView1.Controls
If ctrl.GetType() Is GetType(HScrollBar) Then
If ctrl.Visible = True Then
Return True
Else
Return False
End If
End If
Next
Return Nothing
End Function