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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 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