当我们在文本框C#Windows应用程序中更改时,更改列表框文本 [英] Change Listbox text when we change at textbox C# Windows Application

查看:76
本文介绍了当我们在文本框C#Windows应用程序中更改时,更改列表框文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我有一个列表框,其中从数据库中加载了项目,当用户在文本框中键入任何内容时,列表框应搜索输入的起始字符并将其显示在文本框中.

例如:

用户键入"A"后,在文本框中,则所有从"A"开始的记录应该显示在列表框中.
当用户选择记录并按Enter时,应在文本框中输入该记录.
而且,当用户从鼠标单击记录时,该记录也应在文本"框中输入.

我不想使用文本框自动完成模式

如何在C#Windows应用程序中执行此操作

在此先感谢

Dhinesh kumar.V

Dear All,

I have a list-box where items are loaded from database , when user types anything in text-box, list-box should search the starting characters entered and display it in text-box.

For example :

As soon as User types "A" in text-box ,then all the records starting from "A" should be displayed in List-box.
When user selects the record and press enter,that record should be entered in Text-box.
And also when user clicks the record from mouse,that record should be entered in Text-box.

I don''t want to use text-box auto complete mode

How to do this in C# Windows Application

Thanks in Advance

Dhinesh kumar.V

推荐答案

我假设您使用DataBindingSource,因为您说列表框是数据绑定
并且数据库中的表具有名为Title的列;然后使用这个:

I assumed that you use DataBindingSource as you said list-box is Data-Bound
and your table in DataBase has a Column named Title; then use this:

private void TextBox_TextChanged(object sender, EventArgs e)
{
    BindingSource.Filter = string.Format("Title Like '{0}%'", this.TextBox.Text);
}


愿下面的代码对您有所帮助


May the below code will help you


namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        DataTable DataListSrc = new DataTable();
        public Form1()
        {
            InitializeComponent();
            DataListSrc.Columns.Add("Name");
            DataRow Drow = DataListSrc.NewRow(); Drow["NAME"] = "a"; DataListSrc.Rows.Add(Drow);
            Drow = DataListSrc.NewRow(); Drow["NAME"] = "b"; DataListSrc.Rows.Add(Drow);
            Drow = DataListSrc.NewRow(); Drow["NAME"] = "c"; DataListSrc.Rows.Add(Drow);
            Drow = DataListSrc.NewRow(); Drow["NAME"] = "d"; DataListSrc.Rows.Add(Drow);
            Drow = DataListSrc.NewRow(); Drow["NAME"] = "e"; DataListSrc.Rows.Add(Drow);
            Drow = DataListSrc.NewRow(); Drow["NAME"] = "f"; DataListSrc.Rows.Add(Drow);
            Drow = DataListSrc.NewRow(); Drow["NAME"] = "g"; DataListSrc.Rows.Add(Drow);
            Drow = DataListSrc.NewRow(); Drow["NAME"] = "h"; DataListSrc.Rows.Add(Drow);
            Drow = DataListSrc.NewRow(); Drow["NAME"] = "i"; DataListSrc.Rows.Add(Drow);
            listBox1.DisplayMember = "NAME";
            listBox1.DataSource = DataListSrc;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataView Dv = DataListSrc.DefaultView;
            Dv.RowFilter = "Name like ''" + textBox1.Text + "%''";
            listBox1.DataSource = Dv;
        }
    }
}


使用ajax尝试......

在kextbox的keyup上调用javascript方法.在此方法中,实现ajax代码以获取数据库数据并将其加载到列表框中....

onkeyup ="javascriptmethod()"

k .....
try it using ajax...

on keyup of kextbox call javascript method. inside this method implement ajax code to fetch database data and use it to load to your list box....

onkeyup="javascriptmethod()"

k.....


这篇关于当我们在文本框C#Windows应用程序中更改时,更改列表框文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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