Telerik blogs


GridViewComboBox column is used to display lookup data in user friendly manner. For our demo we bind RadGridView for WPF to a collection of custom Location objects.





As you may notice – each location has a selectable Country field.  Here is the underlying ‘data model’.


public class Location
 public int CountryID { get; set; }
 public string CityName { get; set; }
 public class Country
 public int ID { get; set; }
 public string Name { get; set; }
The location object contains the integer CountryID.Each CountryID corresponds to a certain country and with the help of GridViewComboBoxColumn we see some human readable country names instead of the underlying numeric IDs.

Now The Problem :



Unfortunately the filter control does not know that our Country IDs are associated with Country objects, so it displays the integer CountryIDs . Of course these numbers mean nothing to the end user. We need to let the user chose from a list of country names instead.

The Solution:  

Being a WPF control RadGridView has great customization abilities. The look and the visual behavior of almost any part of the control may be altered without hurting the functionality. Fortunately this includes the filtering control. As mentioned in Rossen's blog we may easily craft the filtering control  to suite our needs.




I have prepared a simple filtering control (see ComboColumnFilteringControl.xaml) with a ListBox inside to display the human-readable distinct values.


Replacing the default filtering control with custom one is easy :


<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CountryID}" Header="Country" DisplayMemberPath="Name" SelectedValueMemberPath="ID" > 
 <local:ComboColumnFilteringControl /> 


The rest of the magic is in the ComboColumnFilteringControl.cs - ready to be copy/pasted.


The whole sample project may be downloaded from the link:


For the purposes of this demo the user control is not exactly visually rich. If you need more complex UI you can easily add any required UI elements into the ComboColumnFilteringControl.xaml.

If you need more complex filtering logic I will recommend to take a look at the following blog , the online example and this help topic.


Comments are disabled in preview mode.