How to select just one item from listview

2019-09-21 00:41发布

问题:

Using Listview with Checkbox

ListView

checkbox id

001
002
003
...

I want to select only one id at a time, and i want to show a selected item in the messagebox

for example

001 id is checked, if i check 002 id means automatically 001 id check should remove, and display a messagebox "002 is Selected"

回答1:

If you use a ListBox, the default behaviour is for only one item to be selected at a time. You can change that behaviour by setting or clearing the .MultiSelect property.

Here is a tutorial you may find helpful.



回答2:

Using a ListView, you will need to go through every other item and make sure it's unchecked when a new item is checked.



回答3:

When the first checkbox is clicked, record a reference in a variable somewhere. When any other checkbox is clicked uncheck the old one by reference, and store a reference to the new one. Much more efficient than looping through everything.



标签: listview vb6