This is a migrated thread and some comments may be shown as answers.

RadGridView Filtering a column with a complex data type (ParserException)

1 Answer 44 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 13 Feb 2014, 06:01 PM
I have a column that is created programmatically and is set to a complex data type.  I need the data type to be complex because I need to override the CompareTo method.  I also want to be able to use textual filtering on this column, via the ToString() method of my type.  When I try to filter on this column, a ParserException is thrown and my program crashes.

consider the following example:

class MyCellType
{
      public string myName;
      public string myParentName;

      public override string ToString()
      {
            return myName;
      }

      public int CompareTo(Object obj)
      {
            //my compare function which sorts children underneath their parents...
            if ( myParentName == ((MyCellType)obj)myParentName )
            {
                 return String.Compare(myName, ((MyCellType)obj)myName);
            }
            else
            {
                return String.Compare(myParentName , ((AdminUnitCell)obj).myParentName );
            }
      }
}


//... code that initializes the grid and a data table

GridViewTextBoxColumn column = new GridViewTextBoxColumn();
column.Name = "MyColumn";
column.HeaderText = "MyColumn";
column.FieldName = "MyColumn";
column.DataType = typeof(MyCellType);
myGrid.MasterTemplate.Columns.Add(column);

myDataTable.Columns.Add("Title", typeof(MyCellType));

//...

myGrid.DataSource = myDataTable;

I looked for a solution to this problem but I could not find a definite answer.  Is textual filtering possible on a complex data type via its ToString() method? If not, then can we get this feature (bug fix) in a future release?   I find it difficult to believe that no has ever had a column with a complex data type on a filter-enabled grid and thus experienced the same crash that I am getting.

Any help would be appreciated.

1 Answer, 1 is accepted

Sort by
0
George
Telerik team
answered on 18 Feb 2014, 01:01 PM
Hi Justin,

Thank you for contacting us.

For such cases you can use the CustomFiltering which RadGridView supports. More information about custom filtering can be found here. Below you can see a sample implementation of the custom filtering:
void Grid_CustomFiltering(object sender, GridViewCustomFilteringEventArgs e)
{
    if (this.Grid.FilterDescriptors.Count > 0)
    {
        e.Visible = e.Row.Cells["MyColumn"].Value.ToString().Contains(this.Grid.FilterDescriptors[0].Value.ToString());
    }
}

I hope this will help you achieve the desired results.

Regards,
George
Telerik
Tags
GridView
Asked by
Justin
Top achievements
Rank 1
Answers by
George
Telerik team
Share this question
or