Results 1 to 8 of 8

Thread: Checkbox in listview?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Checkbox in listview?

    Hi guys, is it possible to have a checkbox in a listview for each item? and when the checkbox is ticked it do some code?

    Thanks
    Jamie

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,269

    Re: Checkbox in listview?

    There is a Checkbox-Property on the Property-Page of ListView and an ItemCheck-Event.....
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3
    Junior Member
    Join Date
    Jul 2012
    Posts
    21

    Re: Checkbox in listview?

    Hi, yes there is one.

    Have a look at this.

    ListView1.Columns.Add("Copyright", 0, HorizontalAlignment.Left)

    ListView1.CheckBoxes = True
    ListView1.View = View.Details
    ListView1.FullRowSelect = True
    ListView1.GridLines = True

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Unhappy Re: Checkbox in listview?

    Thanks a lot guys, really appreciate it, is it possible to add a check box in one of the subitems as appose to the first column in the listview?

    thanks
    Jamie

  5. #5
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,269
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Checkbox in listview?

    Hi guys,

    I'm trying to make a filter listview, like excel's filter option.

    Basically a checkbox of names, and what i want is when you tick each name then it will filter the database with each item checked, at the moment my db string is


    "

    Set rs = db.OpenRecordset("SELECT * FROM `Leads` WHERE `Agent` = " & "'" & listview1.selecteditem & "'")

    how can i make it so agent is what ever the user has ticked?

    Thanks,
    Jamie


    "

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,269

    Re: Checkbox in listview?

    You have to build up your SQL-String dynamically inside the ItemCheck-Event.
    Something like this:
    Code:
    Dim WhereClause as String
    
    Private Sub MyListView_ItemCheck(ByVal Item As MSComctlLib.ListItem)  'I'M DOING THIS IN VBA, SO THE EVENT MIGHT LOOK DIFFERENT IN VB6
    
    If Item.Checked the WhereClause=WhereClause & " AND Agent='" & Item.Text & "'" 'OR USE Item.ListSubItems
    
    DoDatabaseQueryAndRepopulateListView
    
    End Sub
    Obviously you will have to check if it's the first checked item, since then you must not use the " AND"-Operator in your SQL-String

    The Problem you're going to run into:
    Let's say you have 10 different Names first, and you tick off 3 names in your Checkboxlist.
    If you requery your DB with the new SQL-String the other 7 Names will be gone!
    If you really want to do something like Excel's Filter-Thingy you should try to hide the not corresponding lines (that's what Excel is actually doing) without doing a new Query on your DB
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  8. #8
    New Member
    Join Date
    Dec 2018
    Posts
    1

    How to check all checkboxes in listview then display all values by row and column?

    How to check all checkboxes in listview then display all values by row and column in textboxes at visual basic 6.0

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