如何通过C#中的TextBox在DataGridView中搜索记录. [英] How to Search Record in DataGridView Through TextBox in C#.
本文介绍了如何通过C#中的TextBox在DataGridView中搜索记录.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过C#中的TextBox在DataGridView中搜索记录.
(通过选择列)
像这样:
我有一张表格:
Form1(包含DataGridView和一个TextBox).
我在datagridview中选择该列,然后通过文本框搜索记录.
plz,plz,plz,plz,ANyone可以帮助我...
How to Search Record in DataGridView Through TextBox in C#.
(By Selection of column)
Like this:
i have one Form:
Form1(containing DataGridView And One TextBox).
i select the column in the datagridview, and search the record through textbox.
plz,plz,plz,plz, ANyone Can Help Me...
推荐答案
您可以过滤数据,但不确定搜索.
这是您的操作方法.
私人void dataGridView1_ColumnHeaderMouseDoubleClick(object sender,DataGridViewC ....
{
//打开过滤器对话框
//按条件过滤
}
参见本页
> http://stackoverflow.com/questions/5843537/filtering-datagridview-without-changing-datasource [^ ]
私有void textBox1_TextChanged(对象发送者,EventArgs e)
{
MessageBox.Show("DataSource type BEFORE =" + dataGridView1.DataSource.GetType().ToString(),ds.Tables [0] .DefaultView.Count.ToString());
DataView dv = ds.Tables [0] .DefaultView;
dv.RowFilter = string.Format(国家喜欢"%{0}%",textBox1.Text);
dataGridView1.DataSource = dv;
MessageBox.Show("DataSource type AFTER =" + dataGridView1.DataSource.GetType().ToString(),ds.Tables [0] .DefaultView.Count.ToString());
}
You can filter the data but not sure about searching.
Here is how you can do..
private void dataGridView1_ColumnHeaderMouseDoubleClick(object sender, DataGridViewC....
{
//open filter dialog box
//Filter by criteria
}
See this page
http://stackoverflow.com/questions/5843537/filtering-datagridview-without-changing-datasource[^]
private void textBox1_TextChanged(object sender, EventArgs e)
{
MessageBox.Show("DataSource type BEFORE = " + dataGridView1.DataSource.GetType().ToString(), ds.Tables[0].DefaultView.Count.ToString());
DataView dv = ds.Tables[0].DefaultView;
dv.RowFilter = string.Format("country LIKE ''%{0}%''", textBox1.Text);
dataGridView1.DataSource = dv;
MessageBox.Show("DataSource type AFTER = " + dataGridView1.DataSource.GetType().ToString(), ds.Tables[0].DefaultView.Count.ToString());
}
这篇关于如何通过C#中的TextBox在DataGridView中搜索记录.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文