To reproduce:
- Filer twice by a single column with Excel-like filtering.
- The second time InvalidCastException will occur.
Workaround:
- Create custom columns and override the GetDistinctValues method.
public class MyColumn : GridViewTextBoxColumn
{
protected override GridViewColumnValuesCollection GetDistinctValues()
{
int index = this.Index;
if (index >= 0)
{
GridViewColumnValuesCollection distinctValues = new GridViewColumnValuesCollection();
foreach (GridViewRowInfo row in this.OwnerTemplate.Rows)
{
object cellValue = row.Cells[index].Value;
if (!distinctValues.Contains(cellValue))
{
distinctValues.Add(cellValue);
}
}
if (distinctValues.Count > 0)
{
return distinctValues;
}
}
return null;
}
}