Solved

Flexgrid scrollbars

Posted on 2002-05-24
3
932 Views
Last Modified: 2012-08-14
how can i know if the flexgrid is showing its vertical or horizontal scrollbar
0
Comment
Question by:pierrecampe
  • 2
3 Comments
 
LVL 3

Expert Comment

by:Elmo_
ID: 7031638
Pierre,

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


Cheers,

Ed.

0
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 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
0
 
LVL 43

Expert Comment

by:TimCottee
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
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…

828 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