在winform程序中怎么样遍历CheckedListBox中的选中项?
用for循环和foreach分别怎么写?

解决方案 »

  1.   

    http://msdn2.microsoft.com/zh-cn/library/e954th47(VS.80).aspx
      

  2.   

     for (int n = 0; n < CheckBoxList1.Items.Count; n++)
            {
                if (CheckBoxList1.Items[n].Selected)
                {
                    string str = CheckBoxList1.Items[n].Text;  //获取此项
                }
            }
            foreach (ListItem item in CheckBoxList1.Items)
            {
                if (item.Selected)
                {
                    string str1 = item.Text;
                }
            }
      

  3.   

    int count = checkedListBox1.Items.Count;
    for (int i = 0;i<count;i++)
    {
    if (checkedListBox1.GetItemChecked(i))
    {
    MessageBox.Show(checkedListBox1.Items[i].ToString());
    }
    }
      

  4.   

     foreach (ListItem item in CheckBoxList1.Items) 
            { 
                if (item.Selected) 
                { 
                    string str1 = item.Text; 
                } 
            }
    这个ListItem item 不能这么用。这个方法不行。不知道前面应该是个什么
      

  5.   

     for (int n = 0; n  < CheckBoxList1.Items.Count; n++) 
            { 
                if (CheckBoxList1.Items[n].Selected) 
                { 
                    string str += CheckBoxList1.Items[n].Text;  //获取此项 
                } 
            } 
            foreach (ListItem item in CheckBoxList1.Items) 
            { 
                if (item.Selected) 
                { 
                    string str1 += item.Text; 
                } 
            }
      

  6.   

    for (int n = 0; n   < CheckBoxList1.Items.Count; n++)  
            {  
                if (CheckBoxList1.Items[n].Selected)  
                {  
                    string str += CheckBoxList1.Items[n].Text;  //获取此项  
                }  
            }  
            foreach (ListItem item in CheckBoxList1.Items)  
            {  
                if (item.Selected)  
                {  
                    string str1 += item.Text;  
                }  
            }
      

  7.   

    ListItem item   换成 ListViewItem item
      

  8.   

     ListViewItem item  in CheckBoxList1.Items指定的转换无效!
      

  9.   

    7楼的这句话不对 
    CheckBoxList1.Items[n].Selected
    CheckBoxList1.Items[n]这个变成了object类型的了,没有Selected了
      

  10.   

    一堆垃圾 人家是CheckedListBox 不是CheckBoxList 看清楚大哥们
      

  11.   

    人家是CheckedListBox,不是CheckBoxList,看清楚大哥们
      

  12.   

    foreach (object item in checkedListBox1.CheckedItems)
    {
        MessageBox.Show((item as DataRowView).Row[0].ToString());
    }
      

  13.   

    读取: checkedListBox2.GetItemChecked(0);写入:checkedListBox2.SetItemChecked(6,true/false);