EnsureVisible in ListView-VBForums
Results 1 to 6 of 6

Thread: EnsureVisible in ListView

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    7

    EnsureVisible in ListView

    Sorry for my English

    I need to add the function to be marked EnsureVisible row in the listview

    Module load ListView
    Code:
    Public Sub CargarListView_Cliente(LV_Cliente As ListView, rs As ADODB.Recordset)
    On Error GoTo ErrorSub
        LV_Cliente.ListItems.Clear
        If rs.RecordCount > 0 Then
            While Not rs.EOF
                Set objItem = LV_Cliente.ListItems.Add(, , rs(0))
               objItem.SubItems(1) = rs!name
               objItem.SubItems(2) = rs!age
               objItem.SubItems(3) = rs!address
                
                rs.MoveNext
            Wend
        End If
        Exit Sub
    ErrorSub:
        If Err.Number = 94 Then Resume Next
    End Sub

    Form1
    Code:
    Private Sub Form_Load()
        CargarListView_Cliente LV_Cliente, rs
    End Sub
    
    Private Sub LV_Cliente_DblClick()
        Dim i As Integer
        
        With form2
        
            .IdCliente = LV_Cliente.SelectedItem.Text
            
            For i = 1 To 3
                .Text1(i).Text = LV_Cliente.SelectedItem.ListSubItems(i).Text
            Next
            
            .Show vbModal
            
        End With
    
    End Sub
    Form2
    Code:
    Public IdCliente
    
    Private Sub cmdSave_Click()
    
    On Error GoTo ErrorSub
    
            cnn.Execute "UPDATE cliente set name = '" & Trim(Text1(1)) & _
                                             "', age = '" & Trim(Text1(2)) & _
                                             "', address = '" & Trim(Text1(3)) & _
                                             "' where id_cliente = " & IdCliente & ""
        rs.Requery 1
        
        Call CargarListView_Cliente(Form1.LV_Cliente, rs)
        
        DoEvents
        
        Unload Me
        Set Form2 = Nothing
    Exit Sub
    ErrorSub:
    MsgBox Err.Description
    
    End Sub

    Any ideas to add functions

    'LV_Cliente.ListItems.EnsureVisible
    'LV_Cliente.ListItems.Selected = True

  2. #2
    Hyperactive Member
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    319

    Re: EnsureVisible in ListView

    I'm not quite sure I follow, but there's a standard macro for EnsureVisible:
    Code:
    Public Const LVM_FIRST = &H1000
    Public Const LVM_ENSUREVISIBLE = (LVM_FIRST + 19)
    
    Public Function ListView_EnsureVisible(hwndLV As Long, i As Long, fPartialOK As Long) As Boolean
      ListView_EnsureVisible = SendMessage(hwndLV, LVM_ENSUREVISIBLE, ByVal i, ByVal fPartialOK)
    End Function

  3. #3
    PowerPoster
    Join Date
    May 2002
    Posts
    25,755

    Re: EnsureVisible in ListView

    fafalone.... um... that may work... but I don't think that is what's needed...

    pinguinito -- you need to set the selected item to the new item, then make the ITEM ensurevisible....
    against my better judgement.... like this:

    Code:
    Set objItem = LV_Cliente.ListItems.Add(, , rs(0))
    objItem.SubItems(1) = rs!name
    objItem.SubItems(2) = rs!age
    objItem.SubItems(3) = rs!address
    objItem.EnsureVisible
    objItem.Selected = True
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    7

    Re: EnsureVisible in ListView

    Not working,
    Last edited by pinguinito; Feb 10th, 2012 at 09:13 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    7

    Re: EnsureVisible in ListView

    I upload the code to see if anyone can help

    thank you very much
    Attached Files Attached Files

  6. #6

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    7

    Resolved Re: EnsureVisible in ListView

    Public IdCliente
    Dim i As Integer
    Private Sub cmdSave_Click()

    On Error GoTo ErrorSub

    cnn.Execute "UPDATE cliente set name = '" & Trim(Text1(1)) & _
    "', age = '" & Trim(Text1(2)) & _
    "', address = '" & Trim(Text1(3)) & _
    "' where id_cliente = " & IdCliente & ""

    With Form1
    .LV_Cliente.SelectedItem.EnsureVisible
    For i = 1 To 3
    .LV_Cliente.SelectedItem.SubItems(i) = Text1(i)
    Next i
    End With

    DoEvents

    Unload Me
    Set Form2 = Nothing
    Exit Sub
    ErrorSub:
    MsgBox Err.Description

    End Sub
    Last edited by pinguinito; Feb 10th, 2012 at 12:19 PM. Reason: Resolved

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.