How to select just one item from listview

偶尔善良 提交于 2019-12-25 18:46:06

问题


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.



来源:https://stackoverflow.com/questions/8471295/how-to-select-just-one-item-from-listview

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!