Results 1 to 4 of 4

Thread: listview adding check boxes

  1. #1

    Thread Starter
    Hyperactive Member Blacknight's Avatar
    Join Date
    Nov 2002
    Posts
    381

    Resolved listview adding check boxes

    Can I create a column in the listview's report mode in which every time I add another line, this column will have a checkbox and they will be arrayed according to line?
    I.E:
    If i have 3 columns, and I add to the fist and second one the text:
    "col1","col2"
    The code will add a check box instead of text to the line of column three
    Last edited by Blacknight; Oct 17th, 2004 at 06:21 PM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    You can only have the first column of a listview to contain a checkbox
    although you can fake it. Change the positioning so the first
    columns position is in the place you want the checkboxes to be...




    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     'Setup the lvw
    5.     ListView1.Checkboxes = True
    6.     ListView1.ColumnHeaders.Add , , "Col 1"
    7.     ListView1.ColumnHeaders.Add , , "Col 2"
    8.     ListView1.ColumnHeaders.Add , , "Col 3"
    9.     ListView1.HideSelection = False
    10.     ListView1.FullRowSelect = True
    11.     ListView1.LabelEdit = lvwManual
    12.     ListView1.View = lvwReport
    13.     'Add content
    14.     ListView1.ListItems.Add , , "Col 1"
    15.     ListView1.ListItems(1).SubItems(1) = "Col 2"
    16.     ListView1.ListItems(1).SubItems(2) = "Col 3"
    17.     ListView1.ListItems.Add , , "Col 1"
    18.     ListView1.ListItems(1).SubItems(1) = "Col 2"
    19.     ListView1.ListItems(1).SubItems(2) = "Col 3"
    20.     ListView1.ListItems.Add , , "Col 1"
    21.     ListView1.ListItems(1).SubItems(1) = "Col 2"
    22.     ListView1.ListItems(1).SubItems(2) = "Col 3"
    23.     'Chenge the positioning.
    24.     ListView1.ColumnHeaders.Item(1).Position = 3 'Checkbox in column 3
    25.     ListView1.ColumnHeaders.Item(2).Position = 1
    26.     ListView1.ColumnHeaders.Item(3).Position = 2
    27. End Sub
    Attached Images Attached Images  
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member Blacknight's Avatar
    Join Date
    Nov 2002
    Posts
    381
    Thanks!
    I took the code and it worked but I don't get where you set column three to have checkboxes. lets say that I want column two too also have checkboxes, what do I do?
    Edit: NM, saw what you wrote in the begining of your response.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No prob. I think you can sub-class the lv in order to make more
    than one column have checkboxes but its allot of work.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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