且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在下拉列表中添加复选框

更新时间:2023-12-01 15:08:58

如果您使用的是 Windows 应用程序,那么***使用RadListBoxItem"而不是下拉列表.它在 Telerik 中易于使用且使用效率更高.

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();
    }

使用的命名空间是using Telerik.WinControls.UI;