HI,
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 List 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 Gridview.
And also when user clicks the record from mouse,that record should be entered in Gridview.
I don't want to use text-box auto complete mode
Loading
roy himanshuPosted Nov 25, 2009, 2:47 AM
still now iam not getting out put.i entered a letter in text box but items are not displayed in list box.i have one doubt. how to bound the list box to data base.plz help me
Lalit MPosted Nov 25, 2009, 12:50 AM
--------------------------------------
Kirtan PatelPosted Nov 25, 2009, 12:18 AM
Here i coded what you want :)
please check "do you like this answer" check box if it helps you :)
List<string> list = new List<string>();
private void Form1_Load(object sender, EventArgs e)
{
list.Clear();
foreach (String str in listBox1.Items)
{
list.Add(str);
}
}
private void txtSearch_TextChanged(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(txtSearch.Text.Trim()) == false)
{
listBox1.Items.Clear();
foreach (string str in list)
{
if (str.StartsWith(txtSearch.Text.Trim()))
{
listBox1.Items.Add(str);
}
}
}
else if(txtSearch.Text.Trim() == "")
{
listBox1.Items.Clear();
foreach (string str in list)
{
listBox1.Items.Add(str);
}
}
}