I get from the registry a list of installed programs in the ListView . Checkboxes mark the necessary programs. How for example to display the values of selected checkboxes (program names) and write all this into an array?
1 answer
Or we search for Items selected, for example, we make a check that there are selected ones and then take them according to the Checked condition:
if (listView1.Items.Cast<ListViewItem>().Any(x => x.Checked)) { // делаете то, что нужно var lst = listView1.Items .Cast<ListViewItem>() .Where(x => x.Checked) .Select(li => li.Text) .ToList(); // к примеру список строк получите (сделайте ToArray() - вот Вам массив строк) var arr = listView1.Items .Cast<ListViewItem>() .Where(x => x.Checked) .Select(li => li.Text) .ToArray(); // либо вместо Text можете взять Name, вообще то, что Вам нужно берите // и т.д. ... } Or just in the finished CheckedItems we get the selected ones like this:
var lstChecked = new List<string>(); for (int index = 0; index < listView1.CheckedItems.Count; index++) { lstChecked.Add(listView1.CheckedItems[index].Text); } var arrChecked = lstChecked.ToArray(); // в массив or like this:
var arrCh = listView1.CheckedItems.Cast<ListViewItem>().Select(li => li.Text).ToArray(); Two ways to your taste, and that and that are convenient, but I prefer the second - CheckedItems .
What is the result? Select items:
We look in debugging:
Everything works, problems should not arise.
- It only displays 1 checkbox, and if there are several? - g431k
- @ g431k, what does it mean to display only one checkbox? As far as I understand you have a
listView, in which theCheckBoxesproperty is set toTrue, specify your question - Denis Bubnov - I am sorry, it was not correctly formulated. Several checkboxes are selected, and the value it displays only one is g431k
- @ g431k, all the code that I attached - checked, it displays all of my selections, I attached screenshots. Show in debugging what you are doing and what is not working? - Denis Bubnov
- I apologize again, everything works, thanks - g431k
|

