本記事はWindowsアプリケーションのTipsです。
チェック状態を指定して項目を追加するにはItems.Addメソッドを使用します。第1引数に表示する値、第2引数はチェック状態にするならtrue、未チェック状態にするならfalseを指定します。
VBの例
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load CheckedListBox1.Items.Add("A", True) 'チェック CheckedListBox1.Items.Add("B", False) '未チェック CheckedListBox1.Items.Add("C", True) 'チェック CheckedListBox1.Items.Add("C", False) '未チェック CheckedListBox1.Items.Add("D", True) 'チェック End Sub
C#の例
private void Form1_Load(object sender, EventArgs e) { checkedListBox1.Items.Add("A", true); //チェック状態 checkedListBox1.Items.Add("B", false); //未チェック状態 checkedListBox1.Items.Add("C", true); //チェック状態 checkedListBox1.Items.Add("D", false); //未チェック状態 checkedListBox1.Items.Add("E", true); //チェック状態 }
Please follow and like us:
コメント