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

RadComboBox within DataGrid

2 Answers 212 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Geoff Ables
Top achievements
Rank 1
Geoff Ables asked on 23 Sep 2008, 06:00 PM
When I put the RadCombo in a DataGridTemplateColumn, it displays only the first item and selecting the expand error does not expand the list.  The xaml below results in the 'Ascending' Combobox being displayed in each row, but does not allow changing the selection or even showing that there is other selections

<

my:DataGrid x:Name="gridColumns" AutoGenerateColumns="False" >

<my:DataGrid.Columns>

<my:DataGridTextColumn Header="Column Name" DisplayMemberBinding="{Binding ColumnName}"/>

<my:DataGridTextColumn Header="Alias" DisplayMemberBinding="{Binding Alias}"/>

<my:DataGridTextColumn Header="Table" DisplayMemberBinding="{Binding Table}"/>

<my:DataGridCheckBoxColumn Header="Output" DisplayMemberBinding="{Binding Output}"/>

<my:DataGridTemplateColumn Header="Sort Type">

<my:DataGridTemplateColumn.CellTemplate>

<DataTemplate>

<Grid >

<telerik:RadComboBox SelectedItem="{Binding SortType}" >

<telerik:RadComboBoxItem Content="Ascending" />

<telerik:RadComboBoxItem Content="Descending" />

</telerik:RadComboBox>

</Grid>

</DataTemplate>

</my:DataGridTemplateColumn.CellTemplate>

</my:DataGridTemplateColumn>

</my:DataGrid.Columns>

</my:DataGrid>

2 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 25 Sep 2008, 08:13 AM
Hi Geoff,

I managed to reproduce the problem. It appears that the combo box dropdown is not measured correctly when the combo is placed in CellTemplate, but works properly when it is placed in CellEditingTemplate. We are planning an update of RadControls for Silverlight in several days and I will try to include the fix if this problem in it.

Unfortunately, at this moment I am unable to offer a quick workaround, different than using RadComboBox in CellEditingTemplate, instead of CellTemplate.

I am sorry for the inconvenience.

All the best,
Valeri Hristov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Simon Kingaby
Top achievements
Rank 2
answered on 31 Oct 2008, 06:47 PM
This is currently a bug in the Silverlight DataGrid control.  When a ComboBox or RadComboBox is included in a DataGridTemplateColumn.CellEditingTemplate,  the ComboBox dropdown autohides immediately after clicking the dropdown button. 

Manish Dalal's blog has the fix for this:  http://weblogs.asp.net/manishdalal/archive/2008/09/28/combobox-in-datagrid.aspx 

You first create a utility class that will provide the "keep drop list open" service to the combo box, like this:

Imports Telerik.Windows.Controls  
 
Public Class RadComboBoxService  
 
    Public Shared ReadOnly ForceOpenProperty As DependencyProperty = _  
        DependencyProperty.RegisterAttached("ForceOpen"GetType(Boolean), GetType(RadComboBoxService), New PropertyMetadata(AddressOf OnForceOpenChanged))  
 
    Public Shared Function GetForceOpen(ByVal d As DependencyObject) As Boolean 
        Return d.GetValue(ForceOpenProperty)  
    End Function 
 
    Public Shared Sub SetForceOpen(ByVal d As DependencyObject, ByVal value As Boolean)  
        d.SetValue(ForceOpenProperty, value)  
    End Sub 
 
    Private Shared Sub OnForceOpenChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)  
        Dim comboBox = DirectCast(d, RadComboBox)  
        If CBool(e.OldValue) Then 
            RemoveHandler comboBox.Loaded, New RoutedEventHandler(AddressOf comboBox_Loaded)  
        End If 
        If CBool(e.NewValue) Then 
            AddHandler comboBox.Loaded, New RoutedEventHandler(AddressOf comboBox_Loaded)  
        End If 
    End Sub 
 
    Shared Sub comboBox_Loaded(ByVal sender As ObjectByVal e As RoutedEventArgs)  
        Dim comboBox = DirectCast(sender, RadComboBox)  
        If comboBox Is Nothing Then 
            comboBox = DirectCast(e.OriginalSource, RadComboBox)  
        End If 
        comboBox.IsDropDownOpen = True 
    End Sub 
 
End Class 
 

You then use the service in the XAML declaration of your RadComboBox like this:

<data:DataGridTemplateColumn.CellEditingTemplate> 
    <DataTemplate> 
        <telerik:RadComboBox x:Name="DealTypeIdCombo" Margin="1,0,1,0"   
Width="200" DisplayMemberPath="Descr" VerticalAlignment="Center" 
Height="25" SelectedItem="{Binding DealTypeId, Mode=TwoWay}" 
ItemsSource="{Binding SourceDealTypes, Source={StaticResource localItemSource}}" 
local:RadComboBoxService.ForceOpen="true">  
        </telerik:RadComboBox> 
    </DataTemplate> 
</data:DataGridTemplateColumn.CellEditingTemplate> 

Notice the attribute local:RadComboBoxService.ForceOpen="true"
Tags
ComboBox
Asked by
Geoff Ables
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Simon Kingaby
Top achievements
Rank 2
Share this question
or