Click here to Skip to main content
16,021,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey all,

I have created windows form and i what to make search option in that form, i want like this if i entered single letter, the result should be all world which have that singlr letter.

Please Help !!!

Thanks !!
Posted
Comments
Mohamed Mitwalli 24-May-12 7:15am    
what you did so far ?

Hi,

would be interesting in where you get the data from. Database, XML, ...?
However, you can do great search with LINQ.

Example with XML File (could be easily adapted for your goal, important is StartsWith):

C#
var xElem = XElement.Load(@"c:\\adressbook.xml");
                        var name = from names in xElem.Descendants("contact")
                                   where names.Element("name").Value.StartsWith("A", StringComparison.CurrentCultureIgnoreCase)
                                   orderby names.Element("name").Value
                                   select names.Element("name").Value;
                        var matches = Enumerable.Distinct(name);

                        datacontext = matches;
                        ListBox_adressbook.ItemsSource = matches;


Regards
 
Share this answer
 
In the TextChanged event you could use a LINQ query to achive this..

C#
private void txtSearch_TextChanged(object sender, TextChangedEventArgs e)
       {
           TextBox tbox = sender as TextBox;
           string str = tbox.Text;
           var Employee = db.ResourceMasters.Where(p => (p.FirstName.Contains(str) || p.LastName.Contains(str))).Select();

       }


You could put the result as itemsource for the the control you want to display the result..
 
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