C# filtering datagridview
-
Sunday, March 11, 2012 3:59 PMI have a datagridview on the win form and a blindingsource. But what i want to achieve is filter the datagridview to show only the data containing the username which is entered in form1 and only data from the last 7 days. How would i do this? my table contains these colums - ID, cardNumber, amount, date. this table is stored in sqlserver
- Moved by CoolDadTxMVP Monday, March 12, 2012 5:22 PM Winforms related (From:Visual C# General)
All Replies
-
Sunday, March 11, 2012 4:16 PM
The best place to do filtering of this type would be to modify the query string at the datasource or even possibly creating a view on the SQL server that limits the data to your specification and use that as your data source.It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.
- Marked As Answer by Yoyo JiangMicrosoft Contingent Staff, Moderator Tuesday, March 20, 2012 7:41 AM
-
Monday, March 12, 2012 3:00 AM
Hi Welshy10,
I recommend you that there are two ways to filter the field coming from database. The first way is that if your data storage container is DataTable object, you may try using its method named "Select",its MSDN article is http://msdn.microsoft.com/en-us/library/system.data.datatable.select.aspx. The next way is that is that if your data is filled in DataView,you need to use RowFilter to implement the filtering functionality,and you can refer to this thread for more information:http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/e1722276-f964-4858-852d-aac3a02921df.
Sincerely,
Jason Wang
orichisonic http://blog.csdn.net/orichisonic If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
- Marked As Answer by Yoyo JiangMicrosoft Contingent Staff, Moderator Tuesday, March 20, 2012 7:41 AM
-
Monday, March 12, 2012 3:29 AM
Here's an example:
private void GetRowsByFilter()
{
DataTable table = DataSet1.Tables["Orders"];
// Presuming the DataTable has a column named Date.
string expression;
expression = "Date > #1/1/00#";
DataRow[] foundRows;// Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression);// Print column 0 of each returned row.
for(int i = 0; i < foundRows.Length; i ++)
{
Console.WriteLine(foundRows[i][0]);
}
}JP Cowboy Coders Unite!
- Marked As Answer by Yoyo JiangMicrosoft Contingent Staff, Moderator Tuesday, March 20, 2012 7:41 AM
-
Monday, March 12, 2012 3:41 PM
Hello,
please refer this link for filtering data in dataGrid View....
http://www.c-sharpcorner.com/uploadfile/yougerthen/filter-data-dispalyed-in-a-datagridview-using-bindingsource-and-dataview/or not follow this link..
http://www.eggheadcafe.com/community/csharp/2/10041701/c-30--filter-data-in-a-datagridview--rowfilter-property.aspxTarun singh
- Marked As Answer by Yoyo JiangMicrosoft Contingent Staff, Moderator Tuesday, March 20, 2012 7:41 AM


