ComboBox Column

GridViewComboBoxColumn derives from GridViewBoundColumnBase, which means that it inherits all of the functionality too. In addition, GridViewComboBoxColumn provides a RadComboBox editor for editing cell values. It also takes care to translate the Data Member value of the column to the corresponding DisplayMember value of RadComboBox.

IsLightweightModeEnabled - introduced in R2 2016. Setting this property to True is recommended when the DataMemberBinding of the column is not a nested property. Its default value is False. When set to True, the new lightened lookup logic is triggered, thus the performance of GridViewComboBoxColumn is significantly increased. If the column`s DataMemberBinding is a nested property, the value of IsLightweightModeEnabled is not respected.

Here is a list of the most important properties:

  • DataMemberBinding - you should specify the property of the bound business object to relate to SelectedValueMemberPath from column's ItemsSource.

  • ItemsSource - specifies the data source for the RadComboBox editor. It also takes part when translating the Data Member to the Display member.

  • ItemsSourceBinding - allows binding editor's ItemsSource to a member of the bound data item.

  • DisplayMemberPath - member path to display. It points to a field in the assigned GridViewComboBoxColumn.ItemsSource.

  • SelectedValueMemberPath - used in conjunction with DisplayMemberPath in the process of translation of a value to display as content. It also tells the RadComboBox editor which property to use as a Value when the user makes selection.

  • IsComboBoxEditable - allows you to configure whether the editor (RadComboBox) is editable.

  • EmptyText - allows you to set a string which will be displayed in both view mode and edit mode when the RadComboBox editor does not have a selected item. This property is available since R2 2018.

The type of the properties configured as DataMemberBinding and SelectedValueMemberPath should be the same.

Since Q3 2012 SP typing a letter in GridViewComboBoxColumn will point to the first item starting with the same letter.

The following example assumes that you have data as shown in Figure 1:

Figure 1: Sample data structure of RadGridView:

ItemsSource for the ComboBox Column in RadGridView - Telerik's Silverlight DataGrid

Example 1: Define GridViewComboBoxColumn.

<telerik:RadGridView x:Name="radGridView" 
                 AutoGenerateColumns="False"> 
    <telerik:RadGridView.Columns> 
        <telerik:GridViewComboBoxColumn /> 
    </telerik:RadGridView.Columns> 
</telerik:RadGridView> 

Example 2: Define DataMemberBinding.

<telerik:RadGridView AutoGenerateColumns="False"> 
    <telerik:RadGridView.Columns> 
        <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CountryId}" 
                                    UniqueName="Country" /> 
    </telerik:RadGridView.Columns> 
</telerik:RadGridView> 

Example 2: Define DataMemberBinding.

column.DataMemberBinding = new Binding("CountryId"); 
column.UniqueName = "Country"; 

Example 3: Setting ItemsSource.

((GridViewComboBoxColumn)this.radGridView.Columns["Country"]).ItemsSource = RadGridViewSampleData.GetCountries(); 
DirectCast(Me.radGridView.Columns("Country"), GridViewComboBoxColumn).ItemsSource = RadGridViewSampleData.GetCountries() 

Example 4: Configure DisplayMemberPath and SelectedValuePath properties in XAML.

<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding CountryId}" 
                    UniqueName="Country" 
                    SelectedValueMemberPath="Id" 
                    DisplayMemberPath="Name" /> 

Example 4: Configure DisplayMemberPath and SelectedValuePath properties in code.

column.SelectedValueMemberPath = "Id"; 
column.DisplayMemberPath = "Name"; 

The application result should be similar to Figure 2.:

Figure 2: ComboBoxColumn after setting DisplayMemberPath and SelectedValuePath properties.

Setting up the ComboBox Column in RadGridView - Telerik's Silverlight DataGrid

As illustrated in Figure 2 you can map CountryId property of the business object to the respective value in Countries collection via configuring proper DisplayMemberPath.

You can download a runnable project of the previous example from our online SDK repository:ComboboxColumn.

The next example shows how to use ItemsSourceBinding. It allows you to bind the ItemsSource of RadComboBox editor to a collection held by the data item. In this way, you are able to specify different sets of items depending on the entire content of the respective row. The example assumes that you have the data shown in Figure 3:

Figure 3: Sample data structure of RadGridView.

Binding the Telerik Silverlight DataGrid to a Collection of Objects

RadGridView binds to a collection of objects representing the teams. The team object exposes a collection containing the current drivers, which is used as source for the editor. As in the previous example, it also exposes a DriverID property that the column will later translate to an appropriate display value.

Example 5: Configure GridViewComboBoxColumn with ItemsSourceBinding.

<telerik:GridViewComboBoxColumn Header="Driver" 
                    DataMemberBinding="{Binding DriverID}" 
                    UniqueName="Driver" 
                    ItemsSourceBinding="{Binding CurrentDrivers}" 
                    SelectedValueMemberPath="ID" 
                    DisplayMemberPath="Name" /> 

Figure 4. and Figure 5. show the result of configuring ItemsSourceBinding property.

Figure 4. Appearance after setting ItemsSourceBinding property.

ComboBox Column in RadGridView - Telerik's Silverlight DataGrid

Figure 5. Appearance after setting ItemsSourceBinding property.

ComboBox Column of RadGridView - Telerik's Silverlight DataGrid

When using ItemsSourceBinding property, the values displayed in the column’s filtering control will be the values corresponding to the DataMemberBinding (0, 1, 2). If you want to have the displayed ones (S.Vettel, K. Raikkonen, M. Webber), then you need to set GridViewComboBoxColumn.FilterMemberPath to a property containing the values used as DisplayMemberPath.

You can download a runnable project of the previous example from our online SDK repository:ComboboxColumnItemsSourceBinding.

If you are setting GridViewComboBoxColumn's ItemsSource property you should specify a valid Source for it. Please refer to this troubleshooting article.

You can also check the SDK Samples Browser that provides a more convenient approach in exploring and executing the examples in the Telerik XAML SDK repository.

Templating GridViewComboBoxColumn

As of version Q1 2010 SP2, GridViewComboBoxColumn exposes a new property - ItemTemplate - which also applies to the default editor - RadComboBox.

The following example shows how to implement a multi-column ComboBoxColumn.

Start by defining the GridViewComboBoxColumn and its ItemTemplate:

Example 6: Configure GridViewComboBoxColumn with ItemTemplate.

<telerik:GridViewComboBoxColumn Header="City" 
                                DisplayMemberPath="Name" 
                                SelectedValueMemberPath="ID" 
                                ItemsSource="{Binding Path=Cities, Source={StaticResource MyViewModel}}" 
                                Width="*" 
                                DataMemberBinding="{Binding CityID}" > 
    <telerik:GridViewComboBoxColumn.ItemTemplate> 
        <DataTemplate> 
            <Grid> 
                <Grid.ColumnDefinitions> 
                    <ColumnDefinition /> 
                    <ColumnDefinition Width="*"/> 
                </Grid.ColumnDefinitions> 
                <TextBlock Text="{Binding ID}"/> 
                <TextBlock Text="{Binding Name}" Grid.Column="1"/> 
            </Grid> 
        </DataTemplate> 
    </telerik:GridViewComboBoxColumn.ItemTemplate> 
</telerik:GridViewComboBoxColumn> 

The multi-column ComboBoxColumn in this example will have two columns showing the ID and Name of the City respectively. When you run the example, Figure 6 shows the result when the customer tries to edit in a column.

Figure 6.MultiColumnComboBox Column in RadGridView - Telerik's Silverlight DataGrid

See Also

In this article