CheckedListBox用法

//加入项目 

for (int i = 0; i < dtTitle.Rows.Count; i++)
 {
           this.clbTitle.Items.Add(dtTitle.Rows[i][1].ToString());
}

//获取选中的项目

for (int i = 0; i < this.clbTitle.Items.Count; i++)
 {
         if (this.clbTitle.GetItemChecked(i)==true)//全中
         {
                 this.txtDetail.Text = this.txtDetail.Text + this.clbTitle.Items[i].ToString() + "\r\n\r\n";
        }
}

//全选

for (int i = 0; i < this.clbTitle.Items.Count; i++)
{
       this.clbTitle.SetItemChecked(i, true);
}

//反选

 for (int i = 0; i < this.clbTitle.Items.Count; i++)
{
       if (this.clbTitle.GetItemChecked(i) == true)//全中
       {
             this.clbTitle.SetItemChecked(i, false);
       }
      else
       {
             this.clbTitle.SetItemChecked(i, true);
      }
}

 

你可能感兴趣的:(C#)