• <tfoot id='pL4tD'></tfoot>

        <bdo id='pL4tD'></bdo><ul id='pL4tD'></ul>
      <i id='pL4tD'><tr id='pL4tD'><dt id='pL4tD'><q id='pL4tD'><span id='pL4tD'><b id='pL4tD'><form id='pL4tD'><ins id='pL4tD'></ins><ul id='pL4tD'></ul><sub id='pL4tD'></sub></form><legend id='pL4tD'></legend><bdo id='pL4tD'><pre id='pL4tD'><center id='pL4tD'></center></pre></bdo></b><th id='pL4tD'></th></span></q></dt></tr></i><div id='pL4tD'><tfoot id='pL4tD'></tfoot><dl id='pL4tD'><fieldset id='pL4tD'></fieldset></dl></div>
    1. <legend id='pL4tD'><style id='pL4tD'><dir id='pL4tD'><q id='pL4tD'></q></dir></style></legend>

    2. <small id='pL4tD'></small><noframes id='pL4tD'>

      1. 如何获取列表框选定项的值

        How to get listbox selected item value(如何获取列表框选定项的值)

          <small id='8Ve2q'></small><noframes id='8Ve2q'>

          <i id='8Ve2q'><tr id='8Ve2q'><dt id='8Ve2q'><q id='8Ve2q'><span id='8Ve2q'><b id='8Ve2q'><form id='8Ve2q'><ins id='8Ve2q'></ins><ul id='8Ve2q'></ul><sub id='8Ve2q'></sub></form><legend id='8Ve2q'></legend><bdo id='8Ve2q'><pre id='8Ve2q'><center id='8Ve2q'></center></pre></bdo></b><th id='8Ve2q'></th></span></q></dt></tr></i><div id='8Ve2q'><tfoot id='8Ve2q'></tfoot><dl id='8Ve2q'><fieldset id='8Ve2q'></fieldset></dl></div>
          <legend id='8Ve2q'><style id='8Ve2q'><dir id='8Ve2q'><q id='8Ve2q'></q></dir></style></legend>
        • <tfoot id='8Ve2q'></tfoot>

                <tbody id='8Ve2q'></tbody>

                • <bdo id='8Ve2q'></bdo><ul id='8Ve2q'></ul>
                • 本文介绍了如何获取列表框选定项的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 C# .NET 4.0

                  I am working with C# .NET 4.0

                  我正在尝试获取列表框中单个选定项目的值.

                  I am trying to get the value of a single selected item in a listbox.

                  这就是我填充控件的方式:

                  This is how I populate the control:

                  this.files_lb.DataSource = DataTable object
                  

                  在我的设计器中,我将 file_name 指定为 DisplayMember,将 file_id 指定为 DisplayValue

                  In my designer, I have specified file_name as the DisplayMember and file_id as the DisplayValue

                  在列表框中选择一个项目后,我尝试了以下获取值:

                  After selecting an item in the listbox, I tried the following to get the value:

                  this.files_lb.SelectedValue.ToString()
                  

                  但它返回的只是 "System.Data.DataRowView".

                  在此链接:获取所选项目的价值在列表框中作为字符串

                  有人建议-

                  String SelectedItem = listBox1.SelectedItem.Value
                  

                  但是,当我尝试这个时,价值"不是一个选项.

                  However, 'Value' is not an option when I try this.

                  如何从列表框中的单个选定项目中获取 ValueMember 值?

                  How can I get the ValueMember value from a single selected item in a listbox?

                  推荐答案

                  var text = (listBox1.SelectedItem as DataRowView)["columnName"].ToString();

                  columnName 替换为您要从中获取数据的列的名称,这将与您的数据源中的列相对应.

                  Replace columnName with the name of the column you want to get data from, which will correspond with a column in your datasource.

                  如果没有选定的项目,还要注意空值.

                  Also watch out for nulls if there's no selected item.

                  这篇关于如何获取列表框选定项的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)

                  • <bdo id='7zODy'></bdo><ul id='7zODy'></ul>

                      • <legend id='7zODy'><style id='7zODy'><dir id='7zODy'><q id='7zODy'></q></dir></style></legend>

                        <small id='7zODy'></small><noframes id='7zODy'>

                        <tfoot id='7zODy'></tfoot>
                          <tbody id='7zODy'></tbody>
                        <i id='7zODy'><tr id='7zODy'><dt id='7zODy'><q id='7zODy'><span id='7zODy'><b id='7zODy'><form id='7zODy'><ins id='7zODy'></ins><ul id='7zODy'></ul><sub id='7zODy'></sub></form><legend id='7zODy'></legend><bdo id='7zODy'><pre id='7zODy'><center id='7zODy'></center></pre></bdo></b><th id='7zODy'></th></span></q></dt></tr></i><div id='7zODy'><tfoot id='7zODy'></tfoot><dl id='7zODy'><fieldset id='7zODy'></fieldset></dl></div>