以编程方式选择winforms复选框列表中的项目

use*_*618 4 checkboxlist winforms

我无法弄清楚如何以编程方式选择checkboxlist中的项目.

这个cource方法不能编译,但我想告诉你我想得到什么结果.

public ColumnsSelector(Dictionary<string, bool> dataPropertyNames)
            : this()
        {
            foreach (var item in dataPropertyNames)
            {
                checkedListBox1.Items.Add(item.Key);
                checkedListBox1.Items[checkedListBox1.Items.IndexOf(item.Key)].Checked = item.Value;
            }
        }
Run Code Online (Sandbox Code Playgroud)

你怎么强迫这个问题?

Dav*_*man 6

使用CheckedListBox.SetItemCheckState:

checkedListBox.SetItemCheckState(checkedListBox1.Items.Count - 1, CheckedState.Checked);
Run Code Online (Sandbox Code Playgroud)

适用于已选中,未选中和不确定.您还可以使用CheckedListBox.SetItemChecked:

checkedListBox.SetItemChecked(checkedListBox1.Items.Count - 1, true);
Run Code Online (Sandbox Code Playgroud)