<legend id='LcpT1'><style id='LcpT1'><dir id='LcpT1'><q id='LcpT1'></q></dir></style></legend>
<tfoot id='LcpT1'></tfoot>

<small id='LcpT1'></small><noframes id='LcpT1'>

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

        • <bdo id='LcpT1'></bdo><ul id='LcpT1'></ul>
      1. C# 搜索列表框

        时间:2023-10-07
        <legend id='3j8x2'><style id='3j8x2'><dir id='3j8x2'><q id='3j8x2'></q></dir></style></legend>

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

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

                  问题描述

                  我在一个名为 listBox1 的列表框中有大量项目.我在顶部还有一个文本框(textBox1).我希望能够在 textBox 中输入内容,listBox 会搜索它的项目并找到包含我正在输入的内容的项目.

                  I have a large amount of items in a listBox called listBox1. I also have a textBox (textBox1) at the top. I want to be able to type into the textBox and the listBox searches through it's item's and finds ones that contain what I am typing.

                  例如,说 listBox 包含

                  For example, say the listBox contains

                  猫"

                  狗"

                  胡萝卜"

                  和花椰菜"

                  如果我开始输入字母 C,那么我希望它同时显示 Cat 和 Carrot,当我输入 a 时它应该继续显示它们,但是当我添加一个 r 时它应该从列表中删除 Cat.有没有办法做到这一点?

                  If I start typing the letter C, then I want it to show both Cat and Carrot, when I type a it should keep showing them both, but when I add an r it should remove Cat from the list. Is there anyway to do this?

                  推荐答案

                  过滤列表框.试试这个:

                  Filter the listbox. Try this:

                      List<string> items = new List<string>();
                      private void Form1_Load(object sender, EventArgs e)
                      {
                          items.AddRange(new string[] {"Cat", "Dog", "Carrots", "Brocolli"});
                  
                          foreach (string str in items) 
                          {
                              listBox1.Items.Add(str); 
                          }
                      }
                  
                      private void textBox1_TextChanged(object sender, EventArgs e)
                      {
                          listBox1.Items.Clear();
                  
                          foreach (string str in items) 
                          {
                              if (str.StartsWith(textBox1.Text, StringComparison.CurrentCultureIgnoreCase))
                              {
                                  listBox1.Items.Add(str);
                              }
                          }
                      }
                  

                  这篇关于C# 搜索列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:PreviewKeyDown for Windows Store App ListBox 下一篇:如何将上下文菜单添加到 ListBoxItem?

                  相关文章

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

                    1. <tfoot id='wpdrO'></tfoot>

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

                    3. <legend id='wpdrO'><style id='wpdrO'><dir id='wpdrO'><q id='wpdrO'></q></dir></style></legend>
                        <bdo id='wpdrO'></bdo><ul id='wpdrO'></ul>