码迷,mamicode.com
首页 > Windows程序 > 详细

C#遍历CheckedListBox中的勾选项

时间:2017-08-18 22:36:44      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:单击   cte   str   count   int   ted   i++   emc   item   

正确的代码:

string selectedItem = string.Empty;
            for(int i=0; i < checkedListBox1.Items.Count; i++)
            {
                if (checkedListBox1.GetItemChecked(i))
                { selectedItem = selectedItem + " " + checkedListBox1.Items[i].ToString(); }
            }

以下代码只能选择最后单击的那项

string selectedItem = string.Empty;
            for(int i=0; i < checkedListBox1.SelectedItems.Count; i++)
            {
               
                 selectedItem = selectedItem + " " + checkedListBox1.SelectedItems[i].ToString(); 
            }

checked 针对勾选   selected针对单击选择的项  一定要注意哦!

C#遍历CheckedListBox中的勾选项

标签:单击   cte   str   count   int   ted   i++   emc   item   

原文地址:http://www.cnblogs.com/zqyo2000z/p/7392337.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!