在DataGrid中搜索查看并仅显示匹配的项目 [英] Search in DataGrid View and show only matching items

查看:69
本文介绍了在DataGrid中搜索查看并仅显示匹配的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友



我在C#GUI中创建项目,我有一个文本框和一个dataGrid视图。



DataGrid视图我已与数据库绑定。现在我想通过文本框从dataGrid视图中搜索名称。但我希望当我输入文本框时,所以在数据网格视图中只显示包含Ram的文本并隐藏其他值意味着



(首先显示网格中的所有值当我在文本框中键入任何想法时,只有匹配值显示在drid视图中隐藏休息数据。)

Dear Friends

I m creating a project in C# GUI and i have a text box and one dataGrid view.

DataGrid view i have bind with Database. and now i want to search name from dataGrid view through text box. but i want when i type in Text box Ram so in Data Grid View only display the text which contain Ram and hide other value means

(First show all value in grid and when i type any think in textbox then only matching value show in drid view hide rest data.)

推荐答案

你可以使用数据绑定源Filter属性.... 。



http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter.aspx [ ^ ]
you can use Data binding source Filter property.....

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.filter.aspx[^]


您需要编码您可以使用此代码: -

You need to code for that you can use this code:-
if (txt_searchinvoice.Text == "") { MessageBox.Show("Enter Invoice No "); return; }
            using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
            {
                string select = "select * from Invoice where InvoiceNo='" + txt_searchinvoice.Text + "'";
                SqlDataAdapter da = new SqlDataAdapter(select, con);
                DataSet ds = new DataSet();
                da.Fill(ds);
                Dgv_invoice.DataSource = ds.Tables[0];
            }





您可以根据应用程序更改查询和文本框/数据网格视图名称。



You can change the query and text box/ data grid view name according to your application.


这篇关于在DataGrid中搜索查看并仅显示匹配的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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