mccainz2
asked on
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
.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
'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
'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
ASKER
FYI: common courtesey on EE is to post the answer as a comment so as not to lock the question for others. Thanks.
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.
ASKER
everyone thanks for the help, I have a lot of info here and will try to accept an answer within 24 hours.
ASKER
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!
A simple answer is always the most valued....thanks.
Mccainz, a firm believer in the KISS software engineering principle. Keep It Simple Stupid!
ASKER