Results 1 to 7 of 7

Thread: [RESOLVED] Managing ListView Columns (with Checkboxes)

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    48

    Resolved [RESOLVED] Managing ListView Columns (with Checkboxes)

    I started off using a CheckedListBox, but that didn't allow me to control the check boxes as I wished to. I read that a ListView with the CheckBox property set to True would give me more control, so I've recoded for a ListView.

    I'm now stuck as the ListView is 100% loaded and controlled programmatically and I can't figure out how to force the Items added to the ListView into a single column, currently the items insist on loading into two columns at the width of the checkbox:
    Name:  ListViewColumns.png
Views: 781
Size:  1.3 KB

    How can I set the width of the column and force the items into one column?

    Code:
            Dim itm As ListViewItem
            clstFolders.Clear()
    
            With clstFolders
                .Columns.Clear()
                .Columns.Add("Folder Settings")
                .Columns(0).Width = Me.clstFolders.Width
                ' get the list of folders from app.config
                modGlobals.ReadAppConfig(aFolders)                  ' an array of strings
                ' now load the times in to the CheckListBox
                For i = 1 To modGlobals.gFolders
                    itm = New ListViewItem
                    itm.Text = aFolders.GetValue(i)
                    itm.Checked = True
                    .Items.Add(itm)
                Next
            End With
    End Sub
    I'm not sure I'm tying the Items to the Column either, but I can't see how to do that...

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Managing ListView Columns (with Checkboxes)

    Change to the Details view... but if you only have the one col, a list view really isn't the best control to use... A listbox would have been better... what difficulties were you having with it?


    -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??? *

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    48

    Re: Managing ListView Columns (with Checkboxes)

    I couldn't check if the item (string) is checked or not, nor could I change the Checked value when the control was a CheckedListBox

    Code:
    For Each itm in CheckedListBox1.Items
    itm is a String so it seems to be impossible to manipulate the checkbox.

    I can do all this in ListView, but I'm having a problem with the Column...

  4. #4
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: Managing ListView Columns (with Checkboxes)

    Right... it is a string... that's why you use the SetItemchecked method:
    Code:
            For a As Integer = 1 To 10
                Me.CheckedListBox1.Items.Add(a.ToString)
            Next
    
            For a As Integer = 0 To Me.CheckedListBox1.Items.Count - 1
                Me.CheckedListBox1.SetItemChecked(a, True)
            Next
    -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??? *

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    48

    Re: Managing ListView Columns (with Checkboxes)

    Thanks for that, that worked.

    Not obvious, but I'm glad it's there!

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,537

    Re: [RESOLVED] Managing ListView Columns (with Checkboxes)

    Yeah, not completely obvious, but if you think about it, it does make some sense, since the objects in the list could be anything (especially if it's bound to a list or a datatable) so those objects wouldn't have a Checked property... so the CheckedListBox has to handle it... there's also a corresponding GetItemChecked that returns the checked value of the item, as well as a CheckedItems collection property.

    -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??? *

  7. #7

    Thread Starter
    Member
    Join Date
    Jul 2013
    Posts
    48

    Re: [RESOLVED] Managing ListView Columns (with Checkboxes)

    GetItemChecked: Yes I found that, once you told me about the SetItemChecked...

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