Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add Checkboxes to ListView

Status
Not open for further replies.

jalbao

Programmer
Nov 27, 2000
413
US
I have a ListView that uses multiple columns. I would like some of the columns to represent a yes/no value, so intuitively, I would like to use Checkboxes for those columns.

I attempted instantiating a Checkbox object and then adding the Checkbox to my code that adds subitems to my ListView:

Dim theCheckbox As CheckBox
lSingleItem.SubItems.Add(theCheckbox)

This doesn't work.

How do I add Checkboxes to columns in a ListView and then figure out how to grab the status of the Checkbox from a specific column?

tia
 
There is a "Checkboxes" property on your listview. You can use that.
 
Hmm..

I am using it, but from what I can tell, the Checkboxes = true, is nothing more than a UI to select multiple records in the ListView - no different than clicking items with the control key held down.
 
Selected and Checked don't really have anything to do with one another. Add a button to your form, and test it with this code:

Code:
Dim li As ListViewItem
Dim s As String = "Selected:  "
Dim c As String = "Checked:  "
For Each li In ListView1.SelectedItems
       s += li.Text & ", "
Next
For Each li In ListView1.CheckedItems
       c += li.Text & ", "
Next
MsgBox(s & vbCrLf & c)
 
I don't think my question is clear.

I understand the difference between Selected and Checked items. What I don't understand is how to get checkboxes in multiple columns.

Using Checkboxes = true, will only allow for checkboxes in the first column. I, for example, want the Checkboxes in the first, fourth, and fifth columns.

From what I can tell, it looks as though the standard ListView control doesn't support this.

Thanks
 
I don't think so either. Although you might be able to get something that looks presentable.

Dim Chk As New Checkbox()
ListView.Controls.Add(Chk)


You can position it around the listview, and make it "appear" in the correct location.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top