Results 1 to 3 of 3

Thread: [RESOLVED] to check an unchek Listview using String

  1. #1

    Thread Starter
    Fanatic Member mutley's Avatar
    Join Date
    Apr 2000
    Location
    Sao Paulo - Brazil
    Posts
    709

    Resolved [RESOLVED] to check an unchek Listview using String

    Hi

    I Must to read a string like ("850;830;801;819") and to check when in listview, when is equal others values,
    I must to clean checkbox and to check with new values


    How can I do it ?



    tia

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

    Re: to check an unchek Listview using String

    If you need to find item in your listview control try using FindItem method:
    Code:
    Dim itm As MSComctlLib.ListItem
    
        Set itm = ListView1.FindItem("whatever")
        If Not itm Is Nothing Then
            itm.Selected = True
            ' do something
        Else
            ' do something else...
        End If

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: to check an unchek Listview using String

    Something like this?

    Code:
    '~~> Adding Sample Data to Listview
    Private Sub Command1_Click()
        Dim column_header As ColumnHeader, list_item As ListItem
    
        '~~> Create the column headers.
        Set column_header = ListView1.ColumnHeaders.Add(, , "Number", 1000)
    
        '~~> Start with report view.
        ListView1.View = lvwReport
        ListView1.Checkboxes = True
    
        Set list_item = ListView1.ListItems.Add(, , "123")
        Set list_item = ListView1.ListItems.Add(, , "456")
        Set list_item = ListView1.ListItems.Add(, , "850")
        Set list_item = ListView1.ListItems.Add(, , "801")
    End Sub
    
    '~~> Checking the relevant items....
    Private Sub Command2_Click()
        Dim ChkStrg As String, MyArray() As String
        
        ChkStrg = "850;830;801;819"
        MyArray = Split(ChkStrg, ";")
        
        '~~> Clear All the Checks
        For i = 1 To ListView1.ListItems.Count
            ListView1.ListItems(i).Checked = False
        Next i
        
        For i = LBound(MyArray) To UBound(MyArray)
            Dim lstItem As ListItem
            Set lstItem = ListView1.FindItem(MyArray(i), lvwText, , lvwWholeWord)
            If Not lstItem Is Nothing Then
                lstItem.Checked = True
            End If
        Next i
    End Sub
    Last edited by Siddharth Rout; Jun 29th, 2010 at 08:12 AM. Reason: Typo
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

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