Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

how to programatically scroll with a msflexgrid?

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
mccainz2
Asked:
mccainz2
1 Solution
 
TimCotteeHead of Software ServicesCommented:
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
 
mccainz2Author Commented:
thanks Tim, let me push that into code and check it out....as always, hugh de'man
0
 
KingSunCommented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
gajendraCommented:
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
 
harsh008_kCommented:
'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
 
mccainz2Author Commented:
FYI: common courtesey on EE is to post the answer as a comment so as not to lock the question for others. Thanks.
0
 
TimCotteeHead of Software ServicesCommented:
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
 
mccainz2Author Commented:
everyone thanks for the help, I have a lot of info here and will try to accept an answer within 24 hours.
0
 
mccainz2Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now