日期:2014-05-18  浏览次数:20943 次

全面介绍 C#Checklistbox用法(转)

本文从6各方面对c#checklistbox用法做详细介绍,他们分别是c#checklistbox的用法的添加项、判断第0项是否选中、设置第0项是否选中、设置全选、得到全部选中的值、数据绑定。

1、c#checklistbox用法之添加项:

  1. checkedListBox1.Items.Add( "蓝色" ); ?
  2. checkedListBox1.Items.Add( "红色" ); ?
  3. checkedListBox1.Items.Add( "黄色" );?

2、c#checklistbox用法之判断第0项是否选中

  1. if ?(checkedListBox1.GetItemChecked(0))?

3、c#checklistbox用法之设置第0项是否选中

  1. checkedListBox1.SetItemChecked(0,? true );?

4、c#checklistbox用法之设置全选

添加一名为select_all的checkbox控件

  1. private ? void ?select_all_CheckedChanged( object ?sender,?EventArgs?e) ?
  2. ????????{ ?
  3. ???????????? if (select_all.Checked) ?
  4. ???????????????? for ?( int ?j?=?0;?j?<?checkedListBox1.Items.Count;?j++) ?
  5. ????????????????????checkedListBox1.SetItemChecked(j,? true ); ?
  6. ???????????? else ?
  7. ???????????????? for ?( int ?j?=0;?j?<?checkedListBox1.Items.Count;?j++) ?
  8. ????????????????????checkedListBox1.SetItemChecked(j,? false ); ?
  9. ????????}?

5、c#checklistbox用法之得到全部选中的值:

  1. private ? void ?linkLabel_yes_LinkClicked( object ?sender,?LinkLabelLinkClickedEventArgs?e) ?
  2. ???????{ ?
  3. ???????????panel_friend.Visible?=? false ; ?
  4. ???????????button_friend.Text?=? "好友面板" ; ?
  5. ???????????sms_str?=? null ; ?
  6. ??????????? for ?( int ?j?=?0;?j?<?checkedListBox1.Items.Count;?j++) ?
  7. ??????????????? if (checkedListBox1.GetItemChecked(j)) ?
  8. ???????????????{ ?
  9. ??????????????????? //do ?
  10. ???????????????}?? ?
  11. ???????}??

6、c#checklistbox用法之数据绑定

  1. protected ? void ?Page_Load( object ?sender,?EventArgs?e) ?
  2. ????{ ?
  3. ???????? <