按字符串过滤ListBox条目 [英] Filtering ListBox entries by string

查看:110
本文介绍了按字符串过滤ListBox条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有4个项目:
-两个列表框
-一键式
-一个文本框
我有一个包含许多项目的列表框"A",并且
我需要列表框"A"中的列表框"B"中的一个项目.

以下是我要执行的步骤:
1)在文本框中输入单词或字符
2)按一个按钮
3)出现在列表框"B"中的列表应由
的条目组成 如果这些条目以在
中键入的字符串开头,则为列表框"A" 文字框

我需要一些帮助,以获取与文本框中的字符串匹配的列表框"A"中的条目到列表框"B"中的

请帮我解决这个问题.

谢谢!

There are 4 items on my form:
- two listboxes
- one button
- one text box
I have a listbox ''A'' with many items and
I need a item in listbox ''B'' from listbox ''A''.

The following are the steps I''d like to perform:
1)enter a word or character in a textbox
2)press a button
3)The list appearing in ListBox ''B'' should be composed of entries from
ListBox ''A'' if these entries start with the string typed in the
Textbox

I need some help in how to get the entries from ListBox ''A'' that match the string in the TextBox into ListBox ''B''

Please help me solve this.

Thank you!

推荐答案

尝试:
string search = textBox1.Text;
listBox2.Items.Clear();
foreach (string val in listBox1.Items)
    {
    if (val.StartsWith(search))
        {
        listBox2.Items.Add(val);
        }
    }


这篇关于按字符串过滤ListBox条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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