遍历checkedlistboxcontrol

来源:互联网 发布:php精品课程网站源码 编辑:程序博客网 时间:2024/05/21 13:08
实现一、
  1.  for (int i = 0; i < ChkRolelist.ItemCount; i++)
  2.             {
  3.                 if (ChkRolelist.GetItemChecked(i))
  4.                 {
  5.                     _listRole.Add(ChkRolelist.GetItemValue(i).ToString());
  6.                     
  7.                 }
  8.             }

实现二、
  1.             foreach (CheckedListBoxItem var in this.ChkRolelist.Items)
  2.             {
  3.                 if (var.CheckState == CheckState.Checked)
  4.                 {
  5.                     _listRole.Add(var.Value.ToString());
  6.                 }
  7.             }
  8.             for (int i = 0; i < _listRole.Count; i++)
  9.             {
  10.                 MessageBox.Show(_listRole[i].ToString());
  11.             }