使用文本框在Windows表单中进行Advace Seach [英] Advace Seach in Windows form using textbox

查看:151
本文介绍了使用文本框在Windows表单中进行Advace Seach的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我创建了Windows窗体,然后在该窗体中创建搜索选项,如果我输入单个字母,我希望这样,结果应该是所有带有单个字母的世界.

请帮忙!!!

谢谢!!

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 !!

推荐答案



您将从何处获取数据会很有趣.数据库,XML ...?
但是,您可以使用LINQ进行出色的搜索.

XML文件示例(可以很容易地适应您的目标,重要的是StartsWith):

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):

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


在TextChanged事件中,您可以使用LINQ查询来实现这一点.
In the TextChanged event you could use a LINQ query to achive this..

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();

       }



您可以将结果作为要显示结果的控件的itemsource..



You could put the result as itemsource for the the control you want to display the result..


这篇关于使用文本框在Windows表单中进行Advace Seach的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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