Solved

how to programatically scroll with a msflexgrid?

Posted on 2001-08-13
9
371 Views
Last Modified: 2008-02-01
I have a flexgrid whose row headers are the time of the day in 10 minute increments. I would like for my code to be able to look at system time and scroll to the row which corresponds to the closest match when the form loads. So how do I scroll a flexgrid programatically?
0
Comment
Question by:mccainz2
9 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 100 total points
ID: 6379043
Set the .TopRow property of the flexgrid: So if your day starts at lets say 8am and goes up to 7pm that is 11 hours * 6 = 66 rows. So to show the row relating to 3pm that would be 7 * 6 = 42 so .TopRow = 42 will automatically display this row at the top of the grid. The only issue here is if .TopRow > NumberOfRows - RowsDisplayed at one Time then the row that will be displayed is equal to NumberOfRows - RowsDisplayedAtOneTime.
0
 
LVL 5

Author Comment

by:mccainz2
ID: 6379085
thanks Tim, let me push that into code and check it out....as always, hugh de'man
0
 
LVL 1

Expert Comment

by:KingSun
ID: 6379122
I've built a form for similar function as you, but not scroll rows but columns. actually I just modify the data in flexgird, the flexgrid never scroll but it looks like that. if you are interested in it, I can send you the source code.
0
 
LVL 3

Expert Comment

by:gajendra
ID: 6379168
I use...

   .Row = X    ' where x is the row you want to highlight
   .Col = 1
   SendKeys "{Right}"

msflexgrid responds to sendkeys and brings the .Row on the screen (in case it is off screen).

Hope that helps

Gajendra
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Expert Comment

by:harsh008_k
ID: 6379214
'mccainnz this works,i have done for 60 rows
'u can increase for according to ur wish
'u can make adjustments
'but this works fine
Dim irowcnt As Integer
Dim min As Integer
Dim catchmin As Integer
Dim hr As Integer
Dim strDate As String

Call InitializeGrid(fgrid, 60, 1, "Time")

Call SetCellSize(fgrid, 2000)

With fgrid
    For irowcnt = 1 To .Rows - 1

    If irowcnt = 1 Then
    hr = "7"
    .Row = irowcnt
    .Text = hr
    Else
        If min = 50 Then
            hr = hr + 1
            min = 0
        Else
            min = min + 10
        End If
     .Row = irowcnt
      If min = 0 Then
        .Text = hr & ":" & "00"
      Else
        .Text = hr & ":" & min
      End If
    End If
 Next
End With
catchmin = 6
 str = Format(Now, "hh:mm")
 With fgrid
 For irowcnt = 1 To .Rows - 1
   .Row = irowcnt
   .Col = 0


    If Len(str) = 4 Then
      If Mid(.Text, 1, 1) = Mid(str, 1, 1) Then
        For irowcount = irowcount To catchmin
        .Row = irowcount
        .Col = 0
          If Mid(.Text, 3, 1) = Mid(str, 3, 1) Then
              If val(Mid(str, 4, 1)) > 5 Then
                .Row = .Row + 1
                .Col = 0
                Exit Sub
              Else
                .Row = .Row
                .Col = 0
                .FocusRect = flexFocusHeavy
                Exit Sub
              End If
          End If
        Next
    End If
   ElseIf Len(str) = 5 Then
    If Mid(.Text, 1, 2) = Mid(str, 1, 2) Then
        catchmin = .Row + catchmin
        For irowcount = .Row To catchmin - 1
        .Row = irowcount
        .Col = 0
          If Mid(.Text, 4, 1) = Mid(str, 4, 1) Then
              If val(Mid(str, 5, 1)) > 5 Then
                .Row = .Row + 1
                .Col = 0
                .FocusRect = flexFocusHeavy
                Exit Sub
              Else
                .Row = .Row
                .Col = 0
                .FocusRect = flexFocusHeavy
                 Exit Sub
              End If
          End If
        Next
    End If
  End If
 Next
 End With
End Sub

Private Sub InitializeGrid(grd As MSFlexGrid, nrows As Integer, ncols As Integer, ParamArray colnames() As Variant)
''To Initialize Flex Grid
Dim i As Integer
With grd
    .Rows = nrows
    .Cols = ncols
    .FixedCols = 0
    .Row = 0
    For i = 0 To UBound(colnames)
    .Col = i
    .Text = colnames(i)
    Next i
End With
End Sub
Private Sub SetCellSize(grd As MSFlexGrid, ParamArray size() As Variant)
Dim colcount As Integer
Dim i As Integer
colcount = grd.Cols
With grd
    For i = 0 To UBound(size)
    .Col = i
    .ColWidth(i) = CInt(size(i))
    Next i
End With

End Sub

0
 
LVL 5

Author Comment

by:mccainz2
ID: 6379239
FYI: common courtesey on EE is to post the answer as a comment so as not to lock the question for others. Thanks.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6379244
harsh008_k: you are not new to EE so should be aware of the guidelines on comments vs answers. Please re-read this at the bottom of this page. Your solution may well be valid and should have been posted as a comment. It cannot in anyway be treated as the 100% definitive solution to this problem. If you continue to post answers instead of comments your account will be referred to customer services for possible penalty.
0
 
LVL 5

Author Comment

by:mccainz2
ID: 6379267
everyone thanks for the help, I have a lot of info here and will try to accept an answer within 24 hours.
0
 
LVL 5

Author Comment

by:mccainz2
ID: 6379290
I tried Tims solution first and it was so elegant and simple I didnt even bother with the others (sorry).
A simple answer is always the most valued....thanks.
Mccainz, a firm believer in the KISS software engineering principle. Keep It Simple Stupid!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now