如何在C#中使用文本框和Serach按钮搜索datagridview内容 [英] how to search the datagridview content using textbox and serach button in C#

查看:359
本文介绍了如何在C#中使用文本框和Serach按钮搜索datagridview内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中我使用了一个dataGridView,文本框,搜索按钮.........
当我在文本框中写文本并单击搜索按钮......如果datagridview中存在垂直数据,则该行将位于第一个位置

i am creating an application in which i had taken one dataGridView ,textbox, search button............
when i write the text in textbox and click on search button ......if the perticular data is present in datagridview then that row will be at first position

推荐答案

尝试过什么?

您需要在搜索按钮中编写过滤器方法. Filter方法将基于文本框数据过滤数据.为此使用DataView.过滤数据后,将网格与该数据视图重新绑定以查看结果.

试试吧!
Tried anything?

You need to write filter method in your search button. Filter method will filter the data based on textbox data. use DataView for it. Once you have filtered data, rebind the grid with this dataview to see the result.

Try!


我同意S Mewara
单击文本框中的文本,在单击搜索按钮时过滤数据网格的数据源,然后将数据源重新绑定到网格
i agree with S Mewara
Filter teh datasource of the datagrid on click of the search button using the text in the textbox and rebind the datasource to the grid


hello Tushar ..
你可以试试看.

在按钮单击事件(private void button1_Click(对象发送方,EventArgs e))中,您可以创建一个数据表或数据集,您可以在其中传递查询以从数据库中查找数据并在datagridview中反映该数据.

代码将是这样..

hello Tushar..
You can try this..

In the button click event(private void button1_Click(object sender, EventArgs e)) you can create a datatable or dataset in which you can pass the query to find the data from the database and reflect the data in the datagridview.

code will be like this..

private void button1_Click(object sender, EventArgs e)//button click event
{
   DataTable dt= new DataTable;//creation of datatable which will be reflected in                         
                               //the datagrid view
   SqlDataAdapter adpt = new SqlDataAdapter("Select <field> from <table> where <field> like '" + textbox.Text + "%'",connectionobject); //query for database
   adpt.Fill(dt);//datatable to catch the fields from the database
   datagridview.DataSource = dt;
}</field></table></field>


这篇关于如何在C#中使用文本框和Serach按钮搜索datagridview内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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