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

Number of Clicks in the ComboBox Column

If you have a GridViewComboBoxColumn in your RadGridView, then by default, you need to click three times to show the dropdown - the first click selects the current cell, the second enters edit mode and the last one opens the dropdown.

The following solutions allow you to control the number of clicks needed to change the value of the combobox column.

2 Clicks Solution

By configuring EditTriggers="CellClick" property of GridViewComboBoxColumn the cells will enter edit mode with a single click only. Now you will need one more click to show the drop-down and select a value.

1 Click Solution

In addition to configuring the EditTriggers property, you can set OpenDropDownOnFocus property of the RadComboBox editor.

This could be done in XAML by applying a Style targeting the RadComboBox element as an EditorStyle of the column. Example 1 demonstrates how this can be done.

Example 1: Setting the OpenDropDownOnFocus through the EditorStyle property

<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding ClubID}" 
                SelectedValueMemberPath="ID" 
                EditTriggers="CellClick" 
                DisplayMemberPath="Name" 
                ItemsSource="{Binding Clubs}"> 
    <telerik:GridViewComboBoxColumn.EditorStyle> 
    <Style TargetType="telerik:RadComboBox"> 
        <Setter Property="OpenDropDownOnFocus" Value="True"/> 
    </Style> 
    </telerik:GridViewComboBoxColumn.EditorStyle> 
</telerik:GridViewComboBoxColumn> 

If you're using Implicit Styles, you need to base your style on the RadComboBoxStyle.

You can also achieve this in code-behind by handling the PreparingCellForEdit event of the RadGridView control, as shown in Example 2.

Example 2: Handling the PreparingCellForEdit event

private void GridView_PreparingCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e) 
{ 
    var comboBox = e.EditingElement as RadComboBox; 
    if (comboBox != null) 
    { 
        comboBox.OpenDropDownOnFocus = true; 
    } 
} 
Private Sub GridView_PreparingCellForEdit(ByVal sender As Object, ByVal e As GridViewPreparingCellForEditEventArgs) 
    Dim comboBox = TryCast(e.EditingElement, RadComboBox) 
    If comboBox IsNot Nothing Then 
        comboBox.OpenDropDownOnFocus = True 
    End If 
End Sub 

Single-click Selection

In addition, you can have the cell leave edit mode when a selection in the dropdown is made by handling the SelectionChanged event of the combobox. To do so, you need to attach to the PreparedCellForEdit event of the RadGridView control. Example 3 demonstrates a possible approach.

Example 3: Handling the PreparedCellForEdit event

private void GridView_PreparedCellForEdit(object sender, GridViewPreparingCellForEditEventArgs e) 
{ 
    var comboBox = e.EditingElement as RadComboBox; 
    if (comboBox != null) 
    { 
        comboBox.SelectionChanged += (s, a) => 
        { 
            if (a.AddedItems.Count > 0) 
            { 
                (a.OriginalSource as RadComboBox).ParentOfType<GridViewCell>().CommitEdit(); 
            } 
        }; 
    } 
} 
Private Sub GridView_PreparedCellForEdit(ByVal sender As Object, ByVal e As GridViewPreparingCellForEditEventArgs) 
    Dim comboBox = TryCast(e.EditingElement, RadComboBox) 
    If comboBox IsNot Nothing Then 
        AddHandler comboBox.SelectionChanged, Sub(s, a) 
            If a.AddedItems.Count > 0 Then 
                TryCast(a.OriginalSource, RadComboBox).ParentOfType(Of GridViewCell)().CommitEdit() 
            End If 
        End Sub 
    End If 
End Sub 

See Also

In this article