Link to home
Start Free TrialLog in
Avatar of amckenzie
amckenzie

asked on

MSFlexGrid Row Visibility

Does anyone know how to determine if a given row of an MSFlexGrid is currently displayed (in the visible region of the screen), i.e., it has not been scrolled outside of the visible area of the grid?

Failing that, does anyone know how to determine if the vertical scrollbar is visible? (.ScrollBars isn't good enough, that only tells me if the scroll will be displayed when there are enough rows to warrant it)

I've got an MSFlexGrid showing the current contents of an inventory system. I want to jump to a given row (based on the results of a search). I'm selecting the row using .RowSel, but that doesn't make the row visible if it's been scrolled offscreen. I've tried using .toprow to bring the row on-screen, but that hides rows, even if I don't have enough rows to require a scroll bar.

Please note that this form is user resizable, and the grid resizes with it, so answers based on knowing how tall the grid is won't work.
Avatar of twalgrave
twalgrave

Use the RowIsVisible property (there's also a ColIsVisible  property)

if FlexGrid.RowIsVisible(14) = true then





this is jus a model u can do what ever u may want by giving the value to the zzzzz dynamically based on the row or col. selected or searched.
dim zzzzz as integer
z=1
With MSHFlexGrid1
         .col = 0  ' start selection in this column
         .row = zzzzz  ' start selection in this row
         .ColSel = .Cols - 1 ' end selection in this column
         .RowSel = zzzzz  '4 end selection in this row
         .SetFocus
         .Highlight = flexHighlightAlways
         .Visible = True
         .TopRow = zzzzz
End With
ASKER CERTIFIED SOLUTION
Avatar of twalgrave
twalgrave

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The above method is always not correct in every situation please try to use below two functions by rename emMSFlexGrid to your MSFlexGrid's name. These functions will calculate the coordinate of each cell.


Public Function IsHorScroll() As Boolean
    Dim i As Long
    Dim w As Long
    Dim h As Long
    Dim d As Long
    d = 15
    For i = 0 To emMSFlexGrid.Rows - 1 Step 1
        h = h + emMSFlexGrid.RowHeight(i)
    Next
    If h >= emMSFlexGrid.Height - d Then
        d = 270
    End If
   
   
    For i = 0 To emMSFlexGrid.Cols - 1 Step 1
        w = w + emMSFlexGrid.ColWidth(i)
    Next
    If w >= emMSFlexGrid.Width - d Then
        IsHorScroll = True
    Else
        IsHorScroll = False
    End If
End Function
Public Function IsVerScroll() As Boolean
    Dim i As Long
    Dim h As Long
    Dim d As Long
    d = 15
   
    Dim w As Long
    For i = 0 To emMSFlexGrid.Cols - 1 Step 1
        w = w + emMSFlexGrid.ColWidth(i)
    Next
    If w >= emMSFlexGrid.Width - d Then
        d = 270
    End If
   
   
    For i = 0 To emMSFlexGrid.Rows - 1 Step 1
        h = h + emMSFlexGrid.RowHeight(i)
    Next
    If h >= emMSFlexGrid.Height - d Then
        IsVerScroll = True
    Else
        IsVerScroll = False
    End If
End Function
kidmsoft,

<The above method is always not correct in every situation >  Please educate us as to what situations the following method will fail on:

if FlexGrid.RowIsVisible(14) = false then
  FlexGrid.TopRow = 14
  Flexgrid.row = 14
else
  Flexgrid.Row = 14
endif
twalgrave,

Sorry for my impoliteness,I did not read it clearly, because I want only some points for up my question.Now I have not enough points for asking my.

So sorry
Avatar of amckenzie

ASKER

This appears to work properly in the (limited) testing I've done, and since kidmsoft has apparently withdrawn his claim that your code will fail, I am accepting your answer.

Alex