操作checklistbox选中值的方法

来源:互联网 发布:红异端改淘宝 编辑:程序博客网 时间:2024/06/05 01:55

 

方法一

private ArrayList GetCheckedItemsText(CheckedListBox lst_items)
        {
            ArrayList result = new ArrayList();
            IEnumerator myEnumerator;
            myEnumerator = lst_items.CheckedIndices.GetEnumerator();
            int index;

            while (myEnumerator.MoveNext() != false)
            {
                index = (int)myEnumerator.Current;
                lst_items.SelectedItem = lst_items.Items[index];
                result.Add(lst_items.Text);
            }

            return result;
        }

 

方法二:

foreach   (ListItem   li   in   this.checklistbox1)
                    {
                            if   (li.Selected   =   true)
                            {
                                    excelstr   +=   li.ToString()   +   ", ";
                            }
                    }
                    if   (excelstr[excelstr.Length   -   1].ToString()   ==   ", ")
                    {
                            excelstr   =   excelstr.Substring(0,   excelstr.Length   -   1);
                    }
                 
                this.message.Text   =   excelstr;

另可参考:http://social.msdn.microsoft.com/Forums/ro-RO/visualcshartzhchs/thread/f811016c-3ae3-4211-894a-c9054db5dfd6