使用列表框和文本框 [英] Working with listbox and textbox

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

问题描述

嘿,我有一个带有名称和文本框的列表框的胜利表单,我想要实现的是:

Hey guys I have a win form with a listbox with names and a textbox, what i'm trying to achieve is:

当用户在文本框中输入名称时,它将在列表框中选择匹配的名称.任何人都可以帮助或指出我正确的方向.提前谢谢.

when the user enters a name in the textbox it selects the matching name in the listbox. can anyone help or point me in the right direction. thanks in advance.

推荐答案

您好,Nathaniel.Ja,

Hi Nathaniel.Ja,

谢谢您在这里发布.

对于您的问题,请尝试以下代码.

For your question, please try the following code.

  public partial class Form1 : Form
    {
        List<string> _items = new List<string>(); 
        public Form1()
        {
            InitializeComponent();
            _items.Add("One"); 
            _items.Add("Two");
            _items.Add("Three");
            _items.Add("Four");
            _items.Add("Five");

            listBox1.DataSource = _items;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int index = listBox1.FindString(textBox1.Text);
            listBox1.SetSelected(index, true);
        }
    }

我希望这会有所帮助.

最好的问候,

温迪


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

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