如何在列表框wpf中获取多个选定的项目?
我对如何从wpf中的列表框中检索多个选定值感到困惑。
在XAML中,我有以下列表框,选择模式为multiple。
我现在如何检查foreach循环?
foreach (ListItem li in listBox1.Items) { ?? // how to check li is selected or not }
您将在ListBox.SelectedItems中找到它们。
foreach (var item in listBox1.SelectedItems) { }
另一个例子
上述就是C#学习教程:如何在列表框wpf中获取多个选定的项目?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
int j = 0; for (int i = 0; i < lbItems.Items.Count; i++) { if (lbItems.Items[i] == lbItems.SelectedItems[0]) j++; } MessageBox.Show(lbItems.Items.IndexOf(lbItems.SelectedItems[0]).ToString() + string.Format("rnThere are {0} occurences of this object in this list",j) )
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/1020950.html