dev的CheckedComboBoxEdit下拉框控件设置成单选框

只需修改一个属性,写一个事件:

CheckedComboBoxEdit1.Properties.SelectAllItemVisible = false;//下拉框设置成不可全选

#region CheckedComboBoxEdit设置成单选框
        private void CheckedComboBoxEdit1_Popup(object sender, EventArgs e)
        {
            CheckedListBoxControl checkedListBoxControl = (sender as IPopupControl)?.PopupWindow.Controls.OfType<PopupContainerControl>().First().Controls.OfType<CheckedListBoxControl>().First();

            if (checkedListBoxControl != null)
            {
                checkedListBoxControl.ItemCheck -= checkedListBoxControl_ItemCheck;
                checkedListBoxControl.ItemCheck += checkedListBoxControl_ItemCheck;
            }
        }
        private void checkedListBoxControl_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
        {
            if (e.State == CheckState.Checked)
            {
                CheckedListBoxControl list = sender as CheckedListBoxControl;
                List<CheckedListBoxItem> items = new List<CheckedListBoxItem>();
                foreach (int index in list.CheckedIndices)
                {
                    if (index == e.Index) continue;
                    items.Add(list.Items[index]);
                }
                foreach (CheckedListBoxItem item in items)
                    item.CheckState = CheckState.Unchecked;
            }
        }
#endregion

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
通过设置 CellStyle 来实现下拉框单选框、多选框等功能的具体实现步骤如下: 1. 创建下拉框选项。使用 `com.alibaba.excel.write.metadata.style.WriteCellStyle` 类的 `buildDataValidationList` 方法创建下拉框选项。该方法接受两个参数,第一个参数为下拉框选项的列表,第二个参数为下拉框选项的起始行和终止行。例如,以下代码可以创建一个起始行为 1,终止行为 10 的下拉框选项,并将下拉框选项设置为 "选项1"、"选项2"、"选项3": ```java List<String> dropdownList = Arrays.asList("选项1", "选项2", "选项3"); WriteCellStyle dropdownCellStyle = new WriteCellStyle(); dropdownCellStyle.buildDataValidationList(dropdownList, 1, 10); ``` 2. 创建单选框和多选框。使用 `com.alibaba.excel.write.metadata.style.WriteCellStyle` 类的 `buildCheckBox` 方法创建单选框和多选框。该方法接受三个参数,第一个参数为单选框或多选框的值,第二个参数为单选框或多选框的起始行和终止行,第三个参数为单选框或多选框的起始列和终止列。例如,以下代码可以创建一个起始行为 1,终止行为 10,起始列为 A,终止列为 C 的多选框,并将多选框的值设置为 "是": ```java WriteCellStyle checkboxCellStyle = new WriteCellStyle(); checkboxCellStyle.buildCheckBox("是", 1, 10, 0, 2); ``` 3. 将样式应用到单元格。使用 `com.alibaba.excel.write.metadata.style.WriteCellStyle` 类的方法将样式应用到单元格。例如,以下代码可以将上面创建的下拉框单选框和多选框样式应用到单元格: ```java CellData cellData = new CellData("选项1"); cellData.setCellStyle(dropdownCellStyle); CellData cellData2 = new CellData(true); cellData2.setCellStyle(checkboxCellStyle); ``` 通过以上方式,您就可以使用 EasyExcel 库的 CellStyle 来实现下拉框单选框、多选框等功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值