Getting the index of multiple selected items in a listbox using Silverlight

被刻印的时光 ゝ 提交于 2020-01-24 04:38:08

问题


I have a ListBox which is made up of Grid Items in Multiple SelectionMode in Silverlight 3.0.

When I use ListBox.SelectedIndex it only returns the first item which is selected.

I would like to be able see all of the selected items such that it would return all of the selected item indexes' such as; 2, 5, and 7, etc.

Any help?

Cheers,

Turtlepower.


回答1:


You can find the selected indexes by iterating through SelectedItems and finding the objects in the Items property, like this:

List<int> selectedItemIndexes = new List<int>();
foreach (object o in listBox.SelectedItems)
    selectedItemIndexes.Add(listBox.Items.IndexOf(o));

Or if you prefer linq:

List<int> selectedItemIndexes = (from object o in listBox.SelectedItems select listBox.Items.IndexOf(o)).ToList();


来源:https://stackoverflow.com/questions/3836313/getting-the-index-of-multiple-selected-items-in-a-listbox-using-silverlight

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