获取多选列表框的selectedvalues [英] Get selectedvalues of multi-select list box

查看:88
本文介绍了获取多选列表框的selectedvalues的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个处于多选模式的列表框,该列表框是用数据库中的15个值绑定的数据.我有这段代码来显示在列表框中选择的每个项目的选定值:

I have got a list box in multi select mode which is data bound with 15 values from a database. I have this code to display the selected values of each item selected in the list box:

        foreach (var list in list_box.SelectedItems)
        {             
            MessageBox.Show(list_box.SelectedValue.ToString());
        }

不幸的是,显示了正确数量的消息框,但它们仅显示所选列表中第一项的选定值.

Unfortunately, the correct amount of message boxes display but they only display the selected value of the first item in the list that has been selected.

请有人可以帮助我解决这个问题吗?我一直在搜索网络,但找不到一个可以正常工作的示例!

Please can someone help me with this issue? I have been searching the net but I cannot find one example that works correctly!

推荐答案

我回到这个问题并通过以下方法解决了这个问题:

I came back to this issue and solved it by doing this:

  foreach(int blah in multilistbox.SelectedIndices){

  MessageBox.Show(blah.ToString());

  }

感谢您的帮助!

这篇关于获取多选列表框的selectedvalues的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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