Click here to Skip to main content
15,899,679 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Posted
Updated 10-Aug-12 0:33am
v2
Comments
[no name] 10-Aug-12 5:58am    
have you tried out anything yet.??
If yes, show the code....
Dhinesh kumar.V 10-Aug-12 6:34am    
sir i tried by Intellisense but that is only suitable for TextBox.
dimpledevani 10-Aug-12 6:48am    
Write a function that returns you the desired text and call the function on the textchanged event or key pressed event to load it in listbox.On mouseclick event of listitem ,copy the text to your textbox

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:

C#
private void TextBox_TextChanged(object sender, EventArgs e)
{
    BindingSource.Filter = string.Format("Title Like '{0}%'", this.TextBox.Text);
}
 
Share this answer
 
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;
        }
    }
}
 
Share this answer
 
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.....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900