RadComboBox with RadGridView

4 posts, 0 answers
  1. Christy
    Christy avatar
    3 posts
    Member since:
    Dec 2013

    Posted 01 Jul 2014 Link to this post

    I would like to have a combobox that displays a text value when an item is selected but displays a grid with headers when the user clicks on the combobox (see attachment). I used the SelectionBoxTemplate to set the selected item text value and created a comboboxitem with a radgridview inside of it. I cannot use the SelectionBoxTemplate with the radgridview. Is there something wrong with how I have it setup? Also, the radgridview does not update the combobox when an item is selected? How can I make this function like a normal combobox? I don't need autocomplete.



    <telerik:RadComboBox  SelectionBoxTemplate="{StaticResource SelectionBoxTemplate}" 
                                         IsEditable="True" Height="25" Width="200">
                        <telerik:RadComboBox.Items>
                            <telerik:RadComboBoxItem>
                                <telerik:RadComboBoxItem.Template>
                                    <ControlTemplate>
                                        <telerik:RadGridView x:Name="RadGridView1" ShowGroupPanel="False" CanUserFreezeColumns="False" 
                                                 RowIndicatorVisibility="Collapsed" IsReadOnly="True" 
                                                 IsFilteringAllowed="False" ItemsSource="{Binding Tools}" 
                                                 Width="200" Height="150" SelectedItem="{Binding Assignment, Mode=TwoWay}" AutoGenerateColumns="False">
                                            <telerik:RadGridView.Columns>
                                                <telerik:GridViewColumn Header="Item #" HeaderCellStyle="{StaticResource GridViewHeaderCellDefault}">
                                                    <telerik:GridViewColumn.CellTemplate>
                                                        <DataTemplate>
                                                            <TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ItemNumber}" />
                                                        </DataTemplate>
                                                    </telerik:GridViewColumn.CellTemplate>
                                                </telerik:GridViewColumn>
                                                <telerik:GridViewColumn Header="Tool Name" HeaderCellStyle="{StaticResource GridViewHeaderCellDefault}">
                                                    <telerik:GridViewColumn.CellTemplate>
                                                        <DataTemplate>
                                                            <StackPanel>
                                                                <TextBlock Style="{StaticResource TextBlockDefault}" Text="{Binding ToolName}"/>
                                                            </StackPanel>
                                                        </DataTemplate>
                                                    </telerik:GridViewColumn.CellTemplate>
                                                </telerik:GridViewColumn>
                                            </telerik:RadGridView.Columns>
                                        </telerik:RadGridView>
                                    </ControlTemplate>
                                </telerik:RadComboBoxItem.Template>
                            </telerik:RadComboBoxItem>
                        </telerik:RadComboBox.Items>
                    </telerik:RadComboBox>
  2. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 03 Jul 2014 Link to this post

    Hello Christy,

    What I can suggest you would be to modify the NonEditableComboBox Template in order to replace the ItemsPresenter inside with a GridView. Actually I have such an example which demonstrates the exact approach - the selection is working and SelectionBoxTemplate can be applied. Please check the attached sample project and let me know whether it works for you.

    I'm looking forward to hearing from you.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Christy
    Christy avatar
    3 posts
    Member since:
    Dec 2013

    Posted 09 Jul 2014 Link to this post

    Thanks so much for the example. I was able to get it working with a few minor tweaks. I had to remove any foreground or background reference from the ControlTemplate because those resources could not be found. I am also binding the combo box in the xaml. This seems to be working well except my Grid has an extra column, "IsDesignMode". How can I get rid of it?  I'm including my xaml binding in case anyone else would find it helpful.

    <telerik:RadComboBox x:Name="combo" MinWidth="150" ItemTemplate="{StaticResource ComboBoxCustomTemplate}"
                                            NonEditableTemplate="{StaticResource NonEditableComboBox}" HorizontalAlignment="Left"
                                            ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.Tools}"
                                            SelectedItem="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.SelectedSupplyType, Mode=TwoWay}"
                                            SelectedValuePath="ItemNumber" SelectionChanged="combo_SelectionChanged" />
  5. Kalin
    Admin
    Kalin avatar
    1209 posts

    Posted 11 Jul 2014 Link to this post

    Hi Christy,

    I'm glad to hear that the solution is working well for you. As for the addition column, could you please share some more details? Isn't it coming from the ItemsSource you are using (property of the bound objects)?

    I'm looking forward to hearing from you.

    Regards,
    Kalin
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top