Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Flexgrid scrollbars

Posted on 2002-05-24
Medium Priority
Last Modified: 2012-08-14
how can i know if the flexgrid is showing its vertical or horizontal scrollbar
Question by:pierrecampe
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 7031638

I take it that you have set the ScrollBars Property to 3 - FlexScrollBarBoth and that you want to determine when which ones are showing.

Because the scroll bars automatically appear I would think you would need to calculate the Combined height of all the rows to determine if the Horitontal bar is showing and calculate the Combined Width of all the columns to determine if the Vertical scroll bar is showing.

You Could try this.  I have tested it and it works fine.

Private Sub Command1_Click()
Dim i As Integer
Dim Width As Integer
Dim Height As Integer

    i = 0
    For i = 0 To MSFG.Rows - 1
'        MSFG.Row = i
        Height = Height + MSFG.RowHeight(i)
    Next i
    i = 0
    For i = 0 To MSFG.Cols - 1
'        MSFG.Row = i
        Width = Width + MSFG.ColWidth(i)
    Next i
    If MSFG.Height < Height Then
        'Hozizontal scroll bar being displayed
        MsgBox Height & " - Horizontal Bar Being Displayed"
    End If
    If MSFG.Width < Width Then
        'Vertical scroll bar being displayed
        MsgBox Width & " - Vertical Bar Being Displayed"
    End If

End Sub



LVL 43

Accepted Solution

TimCottee earned 800 total points
ID: 7031654
Or you could use an API solution:

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_HSCROLL = &H100000
Private Const WS_VSCROLL = &H200000

Private Sub Command1_Click()
    Dim curstyle As Long
    curstyle = GetWindowLong(MSFlexGrid1.hwnd, GWL_STYLE)
    MsgBox "Vertical = " & ((curstyle Or WS_VSCROLL) = curstyle) & vbLf & "Horizontal = " & ((curstyle Or WS_HSCROLL) = curstyle)
End Sub
LVL 43

Expert Comment

ID: 7031670
You could wrap this into a sub like this to allow it to be used for any control that supports scrollbars:

Private Sub Command1_Click()
    Dim blnVertical As Boolean
    Dim blnHorizontal As Boolean
    WhichScrollbars MSFlexGrid1, blnVertical, blnHorizontal
    MsgBox "MSFlexGrid1 Has " & IIf(blnVertical And blnHorizontal, "Both Scrollbars", IIf(blnVertical And Not blnHorizontal, "Vertical Scrollbar", IIf(blnHorizontal And Not blnVertical, "Horizontal Scrollbar", "No Scrollbars")))
    WhichScrollbars Text1, blnVertical, blnHorizontal
    MsgBox "Text1 Has " & IIf(blnVertical And blnHorizontal, "Both Scrollbars", IIf(blnVertical And Not blnHorizontal, "Vertical Scrollbar", IIf(blnHorizontal And Not blnVertical, "Horizontal Scrollbar", "No Scrollbars")))
End Sub

Private Sub WhichScrollbars(ByRef CtrlToCheck As Object, ByRef Vertical As Boolean, ByRef Horizontal As Boolean)
    Dim lngCurStyle As Long
    lngCurStyle = GetWindowLong(CtrlToCheck.hwnd, GWL_STYLE)
    Vertical = ((lngCurStyle Or WS_VSCROLL) = lngCurStyle)
    Horizontal = ((lngCurStyle Or WS_HSCROLL) = lngCurStyle)
End Sub

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question