Filtering DataGridView OnClick Event (C # WinForm)
How do I filter my datagridview by the value of my label.text on a click event? This is the value from my linq query:
dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>("ageColumn") > 3 &&
c.Field<int>("ageColumn") < 5).Count();
Let's just say that the above query gives me 12 (label.text = 12), now when I click "12" I want my datagridview to only display the 12 rows that match my above query.
source to share
Do you need it to be dynamic? Perhaps store the request itself as a lambda in the Tag property of your tag:
Predicate<DataColumn> clause = c => c.Field<int>("ageColumn") > 3
&& c.Field<int>("ageColumn") < 5;
label1.Tag = clause;
... then reevaluate your query when the label is clicked:
var clause = (sender as Label).Tag as Predicate<DataColumn>;
myDataSource = dataSet.Tables[0].AsEnumerable().Where(clause);
I don't know if this will work, but at least it will allow you to "attach" the where clause to different tables.
I also recommend taking a look at Bindable LINQ so that the results of your queries can be linked. Very cool stuff.
source to share
Now I am not using LINQ, but the logic assumes that whatever is stored is by the expression
dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>("ageColumn") > 3 &&
c.Field<int>("ageColumn") < 5)
Contains the data you are looking for? Isn't there a property for enumerating data?
source to share