Hi guys,
So I was following this telerik video on the 3 types of filtering (basic, excel-like, custom) : https://www.telerik.com/videos/winforms/filtering-and-expressions-in-radgridview-for-winforms
I tried to apply the custom filtering using a textbox just like the video on my project, but I keep getting an error. It's suppose to search all the rows and match what's in the textbox. It'll run, but as soon as I try typing into the textbox, I get an error. What am I doing incorrectly?
I've attached some pics of it and the code as well. Thank you!
Here is my code:
private void ProductionInstructionPrintPage_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dbMTISysDataSet.VW_ProdPrintPage' table. You can move, or remove it, as needed.
this.vW_ProdPrintPageTableAdapter.Fill(this.dbMTISysDataSet.VW_ProdPrintPage);
this.WindowState = FormWindowState.Maximized;
radGridView1.EnableFiltering = true;
radGridView1.EnableCustomFiltering = true;
}
private void radTextBox1_TextChanged(object sender, EventArgs e)
{
radGridView1.MasterTemplate.Refresh();
}
private void radGridView1_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e)
{
// if the custom filter is empty, reset this row to its default state
if (string.IsNullOrEmpty(radTextBox1.Text))
{
e.Visible = true;
//reset each cell in this row
for (int i=0; i<radGridView1.ColumnCount; i++)
{
e.Row.Cells[i].Style.Reset();
e.Row.InvalidateRow();
}
return;
}
//if the custom filter is set, locate the cells in this row that match it and colorize them
e.Visible = false;
for (int i = 0; i<radGridView1.ColumnCount; i++)
{
string text = e.Row.Cells[i].Value.ToString();
//locate and colorize matching cells
if (text.IndexOf(radTextBox1.Text, StringComparison.InvariantCultureIgnoreCase) >= 0)
{
e.Row.Cells[i].Style.CustomizeFill = true;
e.Row.Cells[i].Style.DrawFill = true;
e.Row.Cells[i].Style.BackColor = Color.PowderBlue;
e.Visible = true;
}
else
{
e.Row.Cells[i].Style.Reset();
e.Row.InvalidateRow();
}
}
}