Results 1 to 12 of 12

Thread: Listview subitems.. ensurevisible??

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Listview subitems.. ensurevisible??

    How do I get a listview to scroll over so a sub item is visible?

    Thanks!
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  2. #2
    Frenzied Member d3gerald's Avatar
    Join Date
    Jan 2006
    Posts
    1,348

    Re: Listview subitems.. ensurevisible??

    i cant seem to get what you mean, can you clarify more
    On error goto Trap

    Trap:
    in case of emergency, drop the case...

    ****************************************
    If this post has been resolved. Please mark it as "Resolved" by going through the "Thread Tools" above and clicking on the "Mark Thread Resolved " option.
    if a post is helpful to you, Please Rate it by clicking on the Rate link right below the avatar

  3. #3
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Listview subitems.. ensurevisible??

    Well I was doing an all API approach till i remembered this


    VB Code:
    1. Private Sub ScrollToItem(ByRef lv As ListView, ByVal item As String, column As Long)
    2.     Dim Row As Long
    3.         Row = lv.FindItem(item, column)
    4.         lv.ListItems(Row + 1).EnsureVisible
    5.         lv.ListItems(Row + 1).Selected = True
    6. End Sub

    ScrollToItem ListView1, "83hfhnhf/A", 1

  4. #4

  5. #5
    Admodistrator |2eM!x's Avatar
    Join Date
    Jan 2005
    Posts
    3,900

    Re: Listview subitems.. ensurevisible??

    I read it, but i thought he wanted the whole row highlighted..Well I suck at life

  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Listview subitems.. ensurevisible??

    The following code will scroll a specified column into view.
    VB Code:
    1. Private Declare Function SendMessage _
    2.  Lib "user32.dll" Alias "SendMessageA" ( _
    3.     ByVal hWnd As Long, _
    4.     ByVal wMsg As Long, _
    5.     ByVal wParam As Long, _
    6.     ByRef lParam As Any _
    7. ) As Long
    8.  
    9. Public Sub EnsureVisible( _
    10.  lv As ListView, Item As ListItem, SubColumn As Long)
    11.     Const LVM_FIRST As Long = &H1000
    12.     Const LVM_SCROLL As Long = (LVM_FIRST + 20)
    13.     Dim i As Long
    14.     Dim iX As Long
    15.    
    16.     Item.EnsureVisible
    17.     'Only do the horizontal scrolling if we are in report view
    18.     If lv.View = lvwReport Then
    19.         If SubColumn > 0 And SubColumn <= Item.ListSubItems.Count Then
    20.             For i = 1 To SubColumn + 1
    21.                 iX = iX + lv.ColumnHeaders(i).Width
    22.             Next
    23.             iX = (iX - lv.Width) \ Screen.TwipsPerPixelX
    24.             'First make sure we are fully scrolled to the left
    25.             Call SendMessage(lv.hWnd, LVM_SCROLL, -10000, ByVal 0)
    26.             If iX > 0 Then
    27.                 'Now scroll to the right
    28.                 Call SendMessage(lv.hWnd, LVM_SCROLL, iX, ByVal 0)
    29.             End If
    30.         End If
    31.     End If
    32. End Sub

  7. #7

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Listview subitems.. ensurevisible??

    Thanks Joacim! Perfect
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  8. #8
    Hyperactive Member LucasMKG's Avatar
    Join Date
    Jun 2015
    Location
    South Africa (ZAR)
    Posts
    338

    Re: Listview subitems.. ensurevisible??

    I'm sure Joacim Andersson's solution may be ok...but I adapted it for vhGrid. The only issue is the Column headers get mixed-up and cann't refresh.

    Code:
    EDIT::
    'vhGrid
    'virtual listview
    Public Sub CellEnsureVisible(ByVal SubColumn As Long)
    
        Dim tRClt       As RECT
        Dim tRect       As RECT
        Dim iX As Long
    
        'Only do the horizontal scrolling if we are in grid or report view
        GetClientRect m_lHGHwnd, tRClt
        CellCalcRect RowInFocus, SubColumn, tRect
    
        With tRect
            If .Right > tRClt.Right Then iX = (.Right - tRClt.Right)
            If .left < tRClt.left Then iX = (.left - tRClt.left)
            Call SendMessageLongA(m_lHGHwnd, LVM_SCROLL, iX, ByVal 0)               'Now scroll to the right or left
        End With
    
    End Sub::
    LucasMKG
    getting to the innards of listview
    Last edited by LucasMKG; Jan 27th, 2016 at 06:21 AM.

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: Listview subitems.. ensurevisible??

    What do you mean the column headers get mixed up? Something there is rearranging column order? There's always HDM_ORDERTOINDEX, but I've never needed it even refreshing columns after rearranging their order.

  10. #10
    Hyperactive Member LucasMKG's Avatar
    Join Date
    Jun 2015
    Location
    South Africa (ZAR)
    Posts
    338

    Re: Listview subitems.. ensurevisible??

    - see, attached

    All the refreshing methods seems not to work

    Code:
     Call SendMessage(m_lHdrHwnd, LVM_REDRAWITEMS, TopIndex, ByVal PageCount)
     Call SendMessage(m_lHdrHwnd, LVM_UPDATE, TopIndex + PageCount, ByVal 0) 
     SendMessageLongA m_lHdrHwnd, WM_PAINT, 0&, 0&
     EraseRect m_lHdrHwnd, tRect, 0&
     UpdateWindow m_lHdrHwnd
     UserControl.Refresh
    LucasMKG
    ?
    Attached Images Attached Images  
    Last edited by LucasMKG; Jan 27th, 2016 at 04:41 AM.

  11. #11
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    7,667

    Re: Listview subitems.. ensurevisible??

    What is the problem exactly? Can't tell from the picture.

  12. #12
    Hyperactive Member LucasMKG's Avatar
    Join Date
    Jun 2015
    Location
    South Africa (ZAR)
    Posts
    338

    Re: Listview subitems.. ensurevisible??

    When I move to the right/left the control behaves correctly but the column header is static
    - when I remove HDM_LAYOUT in myWndProc (GXISubclass_WndProc) it behaves correctly...it might have to do with the WINDOWPOS flags


    RESOLVED
    EDIT::
    Code:
    'MyWndProc (GXISubclass_WndProc)
        Case HDM_LAYOUT
            If Not m_bHeaderHide Then
                '/! hey m$, where's the f***ing documentation?
                CopyMemory tHDL, ByVal lParam, Len(tHDL)
                CopyMemory tWPos, ByVal tHDL.lpwpos, Len(tWPos)
                CopyMemory tRect, ByVal tHDL.lprc, Len(tRect)
    
                '/* setwinpos struct
                With tWPos
                    .hWnd = m_lHdrHwnd
                    .hWndInsertAfter = 0&
                    .cx = (tRect.Right - tRect.left)
                    .cy = m_lHeaderHeight
                    .x = tRect.left
                    .y = 0&
    'rem.Seal                .flags = SWP_NOACTIVATE Or SWP_NOZORDER Or SWP_NOMOVE
                    .flags = SWP_NOACTIVATE Or SWP_NOZORDER
                End With
                '/* adjust client rect
                tRect.top = m_lHeaderHeight + 2
                '/* copy and forward
                CopyMemory ByVal tHDL.lprc, tRect, Len(tRect)
                CopyMemory ByVal tHDL.lpwpos, tWPos, Len(tWPos)
                CopyMemory ByVal lParam, tHDL, Len(tHDL)
               ' lReturn = lParam
                bHandled = True
            End If
    - 'SWP_NOMOVE' :: was he culprit...for causing Header not to scroll.

    Thanks fafalone for ensuring that I'm always sorted.

    LucasMKG
    hala to VBForums moderators
    Last edited by LucasMKG; Jan 27th, 2016 at 08:38 AM.

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