Dev控件使用CheckedListBoxControl获取items.count为0 的解决方法

CheckedListBoxControl,我使用DataSource属性,给其绑定了一个List对象。界面显示都挺正常的,当若干个项的复选框被选中的后,它的checkedListBoxControl1.CheckedItems也是正常的。

唯独的问题是在代码中得到的checkedListBoxControl1.Items.Count 为0,自然就不能遍历控件的中的所有项。checkedListBoxControl1能够正确获得某个Item对象的方法就剩下GetItemValue(idx)、SetItemChecked等。

如果你也遇到这种情况,请使用下面的方法来遍历所有的Item,并做出相应的处理:

全不选:

        public void ClearCheckState()
        {
            int idx = 0;
            while (checkedListBoxControl1.GetItemValue(idx) != null)
            {
                checkedListBoxControl1.SetItemChecked(idx, false);
                idx++;
            }
        }
posted @ 2019-09-17 14:39  ogre_zl  阅读(661)  评论(0编辑  收藏  举报