4

チェックボックスリストのアイテムをプログラムで選択する方法がわかりません。

もちろん、この方法はコンパイルされませんが、取得したい結果を示したいと思います。

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;
            }
        }

この問題をどのように強制しますか?

4

2 に答える 2

7

CheckedListBox.SetItemCheckStateを使用します。

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

これは、チェック済み、未チェック、および不確定で機能します。CheckedListBox.SetItemCheckedも使用できます。

checkedListBox.SetItemChecked(checkedListBox1.Items.Count - 1, true);
于 2010-10-25T22:03:41.797 に答える
3
 checkedListBox1.Items.Add(item.Key);
 checkedListBox1.SetItemChecked(checkedListBox1.Items.Count - 1, item.Value);

あるいは単に

 checkedListBox1.Items.Add(item.Key, item.Value);
于 2010-10-25T22:01:49.107 に答える