add checkbox in dropdownlist

好久不见. 提交于 2019-12-25 02:03:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!