PDA

View Full Version : Insert CheckBox to a SubItem of ListView Control



lionne
04-07-2013, 10:30 AM
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.

http://i47.tinypic.com/k4x99g.png

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
http://postimg.org/image/b3ln3orsv/

Aflatoon
04-08-2013, 12:41 AM
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]

lionne
04-10-2013, 07:12 AM
Works like a charm. Thanks Aflatoon!