过滤datagridview行 [英] filter datagridview rows
问题描述
public void readExcelFile()
{
string connectionString =Provider = Microsoft.ACE.OLEDB.12.0; Data Source =+ Properties.Settings.Default.excelFilePath +;扩展属性= \Excel 8.0; HDR = Yes; IMEX = 1\;;
string query = String.Format(select * from [{0} $],Batch Export);
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query,connectionString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
resultsGrid.DataSource = dataSet.Tables [0];
}
现在,当我开始在文本框中输入John,第一列是名称,当我删除字符时,我想要的所有行的名称单元格不以J开头,然后是乔等,我想让行回来。这可能吗?在使用SQL查询到DB之前,我已经做到了,但这个来源是不同的。而且我必须清除每个textChanged事件的表。这里有大约20k行。
在将表分配给resultGrid.DataSource之前,可以使用DataTable.Select:
var strExpr =CustomerFirstName ='John'AND OrderCount> 2;
var strSort =OrderCount DESC;
//使用Select方法查找与过滤器匹配的所有行。
foundRows = ds.Table [0] .Select(strExpr,strSort);
或者您可以使用DataView:
ds.Tables [0] .DefaultView.RowFilter = strExpr;
Hello I have a datagridview that already has many, many rows added to it. I also have a textbox that I want to filter the rows out of the datagridview rows if they do not match. I somehow want to connect the textbox to a column to show AND hide the rows. The table was populated using:
public void readExcelFile()
{
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source = " + Properties.Settings.Default.excelFilePath + "; Extended Properties = \"Excel 8.0;HDR=Yes;IMEX=1\";";
string query = String.Format("select * from [{0}$]", "Batch Export");
OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, connectionString);
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet);
resultsGrid.DataSource = dataSet.Tables[0];
}
Now when I start typing "John" into the textbox and the first column is "Name", I want all the rows whose Name cell doesn't start with "J", then "Jo", etc. when I delete characters, I want the rows to come back. Is this possible? I've done this before using SQL queries to a DB, but this source is different. And I had to clear the table on every textChanged event. There are about 20k rows here.
Before you assign the Table to the resultGrid.DataSource, you can use DataTable.Select:
var strExpr = "CustomerFirstName = 'John' AND OrderCount > 2";
var strSort = "OrderCount DESC";
// Use the Select method to find all rows matching the filter.
foundRows = ds.Table[0].Select(strExpr, strSort);
Or you can use DataView:
ds.Tables[0].DefaultView.RowFilter = strExpr;
这篇关于过滤datagridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!