Results 1 to 9 of 9

Thread: [RESOLVED] MSFLEXGRID - how to get column number of 1st displayed column?

Threaded View

  1. #5
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: MSFLEXGRID - how to get column number of 1st displayed column?

    I'm assuming you mean last visible column/row.

    If so you need to use the .ColIsVisible and .RowIsVisible properties of the Grid in combination with .TopRow and .LeftCol as koolsid touched on and si_the_geek mentioned above.

    The following sample code will display the number of the last visible col/row in a MSFLEXGRID.
    VB Code:
    1. Private Sub uiGetLastVisibleColRows_Click()
    2.     Dim i As Integer
    3.     Dim lastVisible As Integer
    4.    
    5.     lastVisible = 0
    6.    
    7.     For i = MSFlexGrid1.TopRow To (MSFlexGrid1.Rows - 1)
    8.         If ((Not (MSFlexGrid1.RowIsVisible(i))) Or (i = (MSFlexGrid1.Rows - 1))) Then
    9.             lastVisible = (i - MSFlexGrid1.FixedRows)
    10.             Exit For
    11.         End If
    12.     Next i
    13.    
    14.     Call MsgBox("Last visible Row is: " & lastVisible)
    15.    
    16.     lastVisible = 0
    17.    
    18.     For i = MSFlexGrid1.LeftCol To (MSFlexGrid1.Cols - 1)
    19.         If ((Not (MSFlexGrid1.ColIsVisible(i))) Or (i = (MSFlexGrid1.Cols - 1))) Then
    20.             lastVisible = (i - MSFlexGrid1.FixedCols)
    21.             Exit For
    22.         End If
    23.     Next i
    24.    
    25.     Call MsgBox("Last visible Column is: " & lastVisible)
    26. End Sub

    The "MSFlexGrid1.Cols - 1" in the for loop is because .ColIsVisible and .RowIsVisible are 0 based.

    The additional checks on "Or (i = (MSFlexGrid1.Rows - 1))" and "Or (i = (MSFlexGrid1.Cols - 1))" is used to catch the correct values even if the last visible column/row is the actual last column/row in the grid.

    Edit
    To add to si_the_geek's comment on partial rows/columns. When I tested the code any partially shown row and column would be considered visible and .RowIsVisible and .ColIsVisible returned True. I tested more by changing the height/width of the grid at runtime dynamically and it seems that even if only a single pixel is visible the row/column is deemed visible.

    Watch out for that

    Hope this Helps.
    Last edited by Optional; Feb 16th, 2010 at 09:14 AM.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width