Results 1 to 5 of 5

Thread: listview line selection

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2011
    Posts
    17

    Post listview line selection

    example for listbox :

    Private Sub Command1_Click()
    Dim X As Integer
    For X = 0 To List1.ListCount - 1
    List1.Selected(X) = True
    List2.AddItem X
    list
    Next
    End Sub

    i have 2 problems :

    1. assume i have 255 items in listbox1 and i wanna move 20 items in to listbox2 and move the 20 items again with timer1 until the items of listbox1 is finish, how do i do that ?

    2. i wanna change from listbox into listview, the problem is how do i make select the line something like this in listbox =
    List1.Selected(X) = True
    with listview


    VB6 master help me ...


    thanks very much...

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: listview line selection

    If you're using Report View for Listview control then you need to set few other properties to make visual work but in a nutshell all you need is to select ListItem.
    Try sample below:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        With ListView1
            .FullRowSelect = True
            .HideSelection = False
            .View = lvwReport
            
            .ColumnHeaders.Add , , "Col 1"
            .ColumnHeaders.Add , , "Col 2"
            .ColumnHeaders.Add , , "Col 3"
            
            Dim i As Integer
            For i = 1 To 5
                .ListItems.Add , , "Item " & i
            Next i
        End With
    End Sub
    
    Private Sub Command1_Click()
        ListView1.ListItems(3).Selected = True
    End Sub

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: listview line selection

    Btw, instead of Selected property you may also ustilize Listview1.Checkboxes - if set to True a checkbox will appear next to the item on each row.
    To check/uncheck items programmatica lly you will need to use Checked property:
    Code:
    ListView1.ListItems(3).Checked = True
    or toggle the value when item is clicked:
    Code:
    Private Sub ListView1_ItemClick(ByVal Item As MSComctlLib.ListItem)
        Item.Checked = Not Item.Checked
    End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2011
    Posts
    17

    Re: listview line selection

    Ok, i ve got the picture...

    so what about my 1st probs, bro rhino ?

    i use this code but it hang my VB6

    Private Sub Command1_Click()
    Dim A As Integer
    For A = 1 To 20 ' sent 20 items to list2
    List1.ListIndex = A
    List2.AddItem List1.Text
    Next
    pause 0.5

    if list1.listindex < list1.listcount
    doevents
    Dim B As Integer
    For B = 1 To 20 'sent other 20 items
    List1.ListIndex = B
    List2.AddItem List1.Text
    Next
    do until list1.listindex = list1.listcount
    loop
    end if
    end sub

    by the way...thanks for the reply...
    my 2nd probs is solved...

    thanks bro rhino...

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: listview line selection

    Quote Originally Posted by baru_belajar View Post
    1. assume i have 255 items in listbox1 and i wanna move 20 items in to
    Sample below will "move" last 20 items from list1 to list2 every 1 second until list1 is empty:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
    Dim i As Integer
    
        For i = 1 To 255
            List1.AddItem "Item " & i
        Next i
        Timer1.Enabled = False
        Timer1.Interval = 1000 '1 second
    
    End Sub
    
    Private Sub Command1_Click()
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
    Dim i As Integer
    Dim sItem As String
    
        For i = List1.ListCount - 1 To List1.ListCount - 20 Step -1
            If i < 0 Then Exit For
            sItem = List1.List(i)
            List2.AddItem sItem, 0
            List1.RemoveItem (i)
        Next i
        
        Timer1.Enabled = CBool(List1.ListCount)
    
    End Sub
    If you want to move first items instead then you need to modify loop a bit (timer1_timer procedure).

Tags for this Thread

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