问题
I'm using telerik control in my project. I want to add checkbox in drdownlist and select multiple values and store in database. I m using c#.net lang. and it is window base application.
回答1:
if you are using windows application then its better to use "RadListBoxItem" instead of dropdown list. It is easy to use and more efficiently used in Telerik.
for (int i = 0; i < 10; ++i)
{
RadListBoxItem item = new RadListBoxItem();
RadCheckBoxElement checkBox = new RadCheckBoxElement();
checkBox.Text = "Item " + i;
checkBox.ToggleState = i % 2 == 0 ? Telerik.WinControls.Enumerations.ToggleState.On: Telerik.WinControls.Enumerations.ToggleState.Off;
//remove this line if you dont want to close popup on checkbox checked
checkBox.ToggleStateChanged += new StateChangedEventHandler(checkBox_ToggleStateChanged);
item.Children.Add(checkBox);
this.radComboBox1.Items.Add(item);
}
write the above code at load form or at your own desired location. Then write the below code
void checkBox_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
this.radComboBox1.CloseDropDown();
}
and the namespace used is using Telerik.WinControls.UI;
回答2:
You can use the ItemTemplate
Property of the control that you are using and insert a Checkbox
in it. then what is left is merely a matter of binding.
Assuming you are using a RadComboBox
it will look like..
<telerik:RadComboBox ItemsSource="{Binding YourCollectionOfProperties}">
<telerik:RadComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding YourPropertyDescription}" IsChecked="{Binding IsPropertySelected}"/>
</DataTemplate>
</telerik:RadComboBox.ItemTemplate>
</telerik:RadComboBox>
来源:https://stackoverflow.com/questions/22188308/add-checkbox-in-dropdownlist