如何从WPF中的列表框中获取选中的项值字符串? [英] How can I get checked items value string from list box in WPF ?

查看:70
本文介绍了如何从WPF中的列表框中获取选中的项值字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有listBox填充checkItems

我想获取项目值列表中的已检查项目列表框使用wpf。



我尝试了什么:



I have listBox filled with checkItems
I want to get items values string of checked Items List Box Using wpf .

What I have tried:

I tried this  c# code , But this is work only with checkedlist in c# and not same in wpf 

for (int i = 0; i < ListBox.Items.CheckedItems.Count; ++i)
          {
        string ItemValue =ListBox.CheckedItems[i]ToString();
          }





但我只能从listBox wpf中获取所选项目,而不是我想要的:





But I can get only selected Items from listBox wpf using this and its not what I want :

For  (int i = 0; i < ListBox.Items.SelectedItems.Count; ++i)
          {
        string ItemValue =ListBox.SelectedItems[i]ToString();
          }





如何从listBox使用wpf检查项目值?感谢您的帮助和关注。



How can I get checked Items Values from listBox using wpf ? Thank you for any help and attention .

推荐答案

  foreach (CheckBox item in ListBox.Items)
                    {
                        if (item.IsChecked == true)
                        {
                            string ItemValue =item.Content.ToString() ;

}}


这篇关于如何从WPF中的列表框中获取选中的项值字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆