Solved

Flexgrid scrollbars

Posted on 2002-05-24
3
915 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now