Consulting

Results 1 to 3 of 3

Thread: Insert CheckBox to a SubItem of ListView Control

  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    58
    Location

    Insert CheckBox to a SubItem of ListView Control

    Dear all

    I've got one issue, which I unfortunately couldn't solve on my own. How one could insert a CheckBox into a SubItem of a ListView?

    Here's the screenshot of my UserForm. I'd like to have my first column being the last one.



    Here is my code:

    Private Sub UserForm_Activate()
    Dim wb As Workbook
        Dim pc As Worksheet
        Dim Row, tc_num As Integer
    Set wb = Excel.ActiveWorkbook
        Set pc = wb.Sheets("PhysCase")
    Dim li As ListItem
    'count how many test cases are there
        Row = 2
        While Not IsEmpty(pc.Cells(Row, 1))
       Row = Row + 1
       Wend
       tc_num = Row - 1
       'populate the list view
       With Me.lsv_tcList
          .CheckBoxes = True
          .ColumnHeaders.Add , , "STP"
          .ColumnHeaders(1).Width = 25
          .ColumnHeaders.Add , , "ID"
          .ColumnHeaders(2).Width = 25
          .ColumnHeaders.Add , , "TC Name"
          .ColumnHeaders(3).Width = 360
          .HideColumnHeaders = False
          .View = 3
          .Gridlines = True
          .MultiSelect = True
          For Row = 2 To tc_num
             Set li = .ListItems.Add(, , "")
             li.SubItems(1) = pc.Cells(Row, 1).Value
             li.SubItems(2) = pc.Cells(Row, 2).Value
          Next
       End With
    End Sub
    Did anyone experience the same problem?

    Also, when I select the row in a ListBox control, the whole row is selected. Here only the first column. Is there a way to have the same selection behaviour is ListView as in ListBox?

    Any hints will be highly appreciated,
    Regards
    Lionne
    Last edited by Aussiebear; 03-26-2023 at 01:33 AM. Reason: Adjusted code tags

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    You can move the first column with the checkboxes using:
            ' move checkbox column
            .ColumnHeaders(1).Position = 2
    and full row selection is just:
    [Code]
    ' select entire rows
    .FullRowSelect = True
    [/vCode]
    Last edited by Aussiebear; 03-26-2023 at 01:34 AM. Reason: Adjusted code tags
    Be as you wish to seem

  3. #3
    VBAX Regular
    Joined
    Dec 2011
    Posts
    58
    Location
    Works like a charm. Thanks Aflatoon!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •