Add CheckBox to a ComboBox

2 Answers 26 Views
ComboBox General Discussions
Janko
Top achievements
Rank 1
Iron
Janko asked on 20 May 2021, 11:54 AM

Hello everyone,

can anyone post me a simple xaml code snipset to add CheckBox items into a ComboBox?

I searched in the forum but there is no simple example.

I thought something like this


<telerik:RadComboBox>
                            <telerik:RadComboBox.ItemTemplate>
                                <DataTemplate>
                                    <kzv:KzvCheckBox/>
                                </DataTemplate>
                            </telerik:RadComboBox.ItemTemplate>
                            <telerik:RadComboBoxItem Content="Test"/>
                        </telerik:RadComboBox>

But the CheckBox is still missing

Thanks for your help.

2 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 25 May 2021, 06:59 AM

Hello Janko,

ItemTemplate is used with the ItemsSource of the control. In case you defined RadComboBoxItem objects directly in the Items collection, the ItemTemplate won't work. 

To achieve your requirement, you can define the CheckBox directly into the Content of the RadComboBoxItem element.

<telerik:RadComboBoxItem>
	<telerik:RadComboBoxItem.Content>
		<kzv:KzvCheckBox/>
	</telerik:RadComboBoxItem.Content>
</telerik:RadComboBoxItem>

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

0
Janko
Top achievements
Rank 1
Iron
answered on 26 May 2021, 07:33 AM

I tryed now this

<telerik:RadComboBox>
  <telerik:RadComboBoxItem>
     <telerik:RadComboBoxItem.Content>
         <CheckBox Content="Test 1"/>
         <CheckBox Content="Test 2"/>
     </telerik:RadComboBoxItem.Content>
   </telerik:RadComboBoxItem>
</telerik:RadComboBox>

But I cant define a second Checkbox in the Content. And it has a really strange Behavior. The CheckBox shows up on the front of my MainView totaly outside of the ComboBox in debug mode.

Martin Ivanov
Telerik team
commented on 26 May 2021, 10:07 AM

The Content property allows you to define only a single object. To define more than one UI elements, like CheckBoxes, you will need to wrap them in an items panel. For example, you can use a StackPanel or a Grid.

<telerik:RadComboBoxItem.Content>
<StackPanel>
<CheckBox Content="Test 1"/>
<CheckBox Content="Test 2"/>
</StackPanel>
 </telerik:RadComboBoxItem.Content>

 

 

Tags
ComboBox General Discussions
Asked by
Janko
Top achievements
Rank 1
Iron
Answers by
Martin Ivanov
Telerik team
Janko
Top achievements
Rank 1
Iron
Share this question
or