New to Telerik UI for WPF? Download free 30-day trial

Empty Cells in Combobox column

PROBLEM

When you use the GridViewComboBoxColumn you might encounter empty cells in that column:

Telerik WPF DataGrid troubleshoot blank cells

CAUSE

First, you need to check:

  • The Output for Binding exceptions.
  • If the types are of the same type.
  • If the DisplayMemberPath property is set correctly.

If you do not encounter any of the above-mentioned problems, then you probably use ElementName binding for that column, e.g.

Example 1: Binding with ElementName

<telerik:GridViewComboBoxColumn Header="Category" 
DataMemberBinding="{Binding CategoryID}" 
ItemsSource="{Binding Path=DataContext.Categories, ElementName=RootElement}" 
DisplayMemberPath="CategoryName" 
SelectedValueMemberPath="CategoryID" /> 

This will not work, as the DataContext of the cell would not be the ViewModel, but the business object related to the row instead. We do not recommend such approach.

SOLUTION

There are two ways of solving the issue :

Setting the ItemsSource of GridViewComboBoxColumn

  • Expose the ViewModel as a static resource on the page so that it can be easily accessible by the binding:

Example 2: Exposing the ViewModel as a Static Resource

<UserControl.Resources> 
    <local:MyViewModel x:Key="MyViewModel" /> 
</UserControl.Resources> 
  • Set the ItemsSource of the ComboBox column:

Example 3: Setting the ItemsSource of GridViewComboBox declaratively

<telerik:GridViewComboBoxColumn Header="Category" 
DataMemberBinding="{Binding CategoryID}" 
ItemsSource="{Binding Path=Categories, Source={StaticResource MyViewModel}}" 
DisplayMemberPath="CategoryName" 
SelectedValueMemberPath="CategoryID" /> 

Example 4: Setting the ItemsSource of GridViewComboBoxColumn programmatically

private void gridView_DataLoaded(object sender, EventArgs e) 
{ 
    (this.radGridView.Columns["Category"] as GridViewComboBoxColumn).ItemsSource = GetCategories(); 
} 
Private Sub gridView_DataLoaded(ByVal sender As Object, ByVal e As EventArgs) 
    TryCast(Me.radGridView.Columns("Category"), GridViewComboBoxColumn).ItemsSource = GetCategories() 
End Sub 

Setting the IsLightWeightModeEnabled property

As of R2 2016 GridViewComboBoxColumn exposes the IsLightWeightModeEnabled. When set to True, a completely new lookup logic is used, which improves the performance of the column and could be a solution for a scenario when having empty cells in it. More information can be found in the ComboBoxColumn topic.

See also

In this article