Reputation: 179
I have data gridview and in one colum contain numeric values and i am trying to apply filters like show greater and etc but I am not able to come with solution.
screen:
code:
calling the class method and assigning the value to datagridview
dataGridViewKeywords = filter.Filter(dataGridViewKeywords, mainValue, true);
Class File:
class FilterDataGridView
{
private DataGridView modifiedDGV = new DataGridView();
private string keyword;
private int competionScore;
DataTable dt = new DataTable();
public DataGridView Filter (DataGridView dgv, int value, bool isabove)
{
modifiedDGV.Columns.Add("keyword", "Keyword") ;
modifiedDGV.Columns.Add("competition", "Avg. Competition Score");
modifiedDGV.Columns.Add("moreinfo", "More Info");
if (isabove)
{
for (int row = 0; row < dgv.Rows.Count; row++)
{
competionScore = Convert.ToInt32(dgv.Rows[row].Cells[1].Value);
keyword = dgv.Rows[row].Cells[0].Value.ToString();
if (competionScore > value)
modifiedDGV.Rows.Add(keyword, competionScore, "View");
}
}
return modifiedDGV;
}
Upvotes: 0
Views: 385
Reputation: 1001
The cleanest solution is to work with BindingSource
.
You provide your data within a BindingSource
-class and set the DataGridView.DataSource
to this BindingSource
.
BindingSource
itself is more or less a better List and also has a Filter
-property which lets you apply the criteria very easy. This way you don't have to mess around with all these items and even create a second DataGridView
.
Upvotes: 1