Click here to Skip to main content
13,346,487 members (63,932 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
i Have one textbox if i enter character A then it should show list of data related to character A into Listbox.
Posted 14-Sep-12 20:10pm
Comments
manoj kumar choubey 15-Sep-12 2:03am
   
Hi for windows app / web app ?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi Sam, You can use following code:
int index = listBox1.FindString(this.textBox1.Text);
if(0 < index)
{
  listBox1.SelectedIndex = index;
  listBox1.TopIndex = listBox1.SelectedIndices[0];
}


On textBox1_Click event:
textBox1.Select(textBox1.Text.IndexOf(textBox1.text), textBox1.Text.Length);
textBox1.Focus();


Hope it will help you.
  Permalink  
v2
Comments
SamWakchaure 15-Sep-12 2:29am
   
i want to retrive entries from database.
Raje_ 15-Sep-12 2:31am
   
So what is your problem? Just bind your DataSource with ListBox control.
http://msdn.microsoft.com/en-us/library/w67sdsex.aspx
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

use DataBindingDource.Filter:

public void textBox1_TextChanged(object sender, EventArgs e)
{
    string filter = string.Format("Column_Name Like '%{0}%'", textBox1.Text.Replcae("'", "''").Replace("[", "[[]");

    // Column_Name iscolumn name of a table that you have bounded to the listBox
    BindingSource.Filter = filter;
}
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.180111.1 | Last Updated 15 Sep 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100