开发者

Programmatically selecting items in winforms checkboxlist

开发者 https://www.devze.com 2023-01-22 10:36 出处:网络
I can\'t figure out how to programmatically select items in checkboxlist. This method of cource doesn\'t compile, but I want to show you what a result I want to get.

I can't figure out how to programmatically select items in checkboxlist.

This method of cource doesn't compile, but I want to show you what a result I want to get.

public ColumnsSelector(Dictionary<string, bool> dataPropertyNames)
            : this()
        {
            foreach (var item in dataPropertyNames)
            {
                checkedListBox1.Items.Add(item.Key);
                checkedListBox1.Items[ch开发者_如何学PythoneckedListBox1.Items.IndexOf(item.Key)].Checked = item.Value;
            }
        }

How do you force with this problem?


Use CheckedListBox.SetItemCheckState:

checkedListBox.SetItemCheckState(checkedListBox1.Items.Count - 1, CheckedState.Checked);

which works for checked, unchecked, and indeterminate. You can also use CheckedListBox.SetItemChecked:

checkedListBox.SetItemChecked(checkedListBox1.Items.Count - 1, true);


 checkedListBox1.Items.Add(item.Key);
 checkedListBox1.SetItemChecked(checkedListBox1.Items.Count - 1, item.Value);

or just

 checkedListBox1.Items.Add(item.Key, item.Value);
0

精彩评论

暂无评论...
验证码 换一张
取 消