2010-10-25 108 views
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; 
      } 
     } 

你如何解決這個問題的力量?

回答

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

或只是

checkedListBox1.Items.Add(item.Key, item.Value); 
相關問題