DEV的CheckedBoxList单选的问题

    技术2022-05-20  30

    使用DEV的CheckedBoxList时遇到单选的问题,根据以往的经验来说,是通过Items来遍历操作,但是这个控件比较奇怪, 如果是我们自己手动添加的项目的话(数据不来自于查询),Items中有项目,但是一旦给DataSoure设置数据源后Items 中就没有项目了,Items.Count=0(一直),没有找到原因,因而用来外一种方式,通过索引来实现。 ---------------------------------------------------------------------------------------------------------------------------------------------

    /// <summary>

            /// 实现单选

            /// </summary>

            private void checkedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)

            {

                //如果状态为选中

                if (e.State == CheckState.Checked)

                {

                    //循环遍历项目

                    for (int i = 0; i < checkedListBoxControl1.ItemCount; i++)

                    {

                        //把非当前的项目全部设置为没选中

                        if (i != e.Index)

                            checkedListBoxControl1.SetItemCheckState(i, CheckState.Unchecked);

                    }

                }

            }


    最新回复(0)