<tfoot id='w9Oa8'></tfoot>

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

        C# - 无法在 WinForms 的列表框中执行键值操作

        C# - Cannot do Key-Value in a ListBox in WinForms(C# - 无法在 WinForms 的列表框中执行键值操作)

            <bdo id='Yenp9'></bdo><ul id='Yenp9'></ul>
          • <tfoot id='Yenp9'></tfoot>

          • <small id='Yenp9'></small><noframes id='Yenp9'>

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

                    <tbody id='Yenp9'></tbody>
                  本文介绍了C# - 无法在 WinForms 的列表框中执行键值操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 WinForms 中的 ListBox 编写 C# 应用程序.

                  I'm writing a C# app using a ListBox in WinForms.

                  我从一个 XML 文件中获取我的数据(ID 和全名).我想在列表框中显示全名,当我选择其中一个时,我想获取相关的 id.

                  I get my data (id and full name) from an XML file. I want to show full names in the listbox and when I select one of them, I want to get the relevant id.

                  我尝试使用 SelectedValue 属性,但没有成功.

                  I tried using SelectedValue property with no luck.

                  我也试过 KeyValuePair,它在列表框中显示[full name, id]",这不是我想要的:

                  I also tried KeyValuePair and it shows "[full name, id]" in the listbox, which is not what I wanted:

                  LB_UserList.Items.Add(new KeyValuePair<string, string>(full_name, node["user_id"].InnerText));
                  

                  简而言之,如何在 C# 中模拟 HTML 选择?我想在列表框中显示全名并在后端获取相关 id.

                  How can I simulate a HTML select in C# in short? I want to show full names in the listbox and to get relevant id in the backend.

                  推荐答案

                  使用c# 字典为此,

                  Dictionary<string, string> list = new Dictionary<string, string>();
                  list.Add("item 1", "Item 1");
                  list.Add("item 2", "Item 2");
                  list.Add("item 3", "Item 3");
                  list.Add("item 4", "Item 4");
                  
                  dropdown.DataSource = list;
                  dropdown.DataTextField = "Value";
                  dropdown.DataValueField = "Key";
                  dropdown.DataBind();
                  

                  <小时>

                  listBox.DataSource = new BindingSource(list, null); 
                  listBox.ValueMember = "Key";
                  listBox.DisplayMember = "Value"; 
                  

                  这篇关于C# - 无法在 WinForms 的列表框中执行键值操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 列表框上的取消选择)

                  <tfoot id='KVihz'></tfoot>
                  <i id='KVihz'><tr id='KVihz'><dt id='KVihz'><q id='KVihz'><span id='KVihz'><b id='KVihz'><form id='KVihz'><ins id='KVihz'></ins><ul id='KVihz'></ul><sub id='KVihz'></sub></form><legend id='KVihz'></legend><bdo id='KVihz'><pre id='KVihz'><center id='KVihz'></center></pre></bdo></b><th id='KVihz'></th></span></q></dt></tr></i><div id='KVihz'><tfoot id='KVihz'></tfoot><dl id='KVihz'><fieldset id='KVihz'></fieldset></dl></div>
                  • <small id='KVihz'></small><noframes id='KVihz'>

                        <bdo id='KVihz'></bdo><ul id='KVihz'></ul>

                        <legend id='KVihz'><style id='KVihz'><dir id='KVihz'><q id='KVihz'></q></dir></style></legend>

                              <tbody id='KVihz'></tbody>