如何在窗口中检查arraylist中的checkboxlist项目表格c# [英] How To check checkboxlist items from arraylist in window Form c#

查看:89
本文介绍了如何在窗口中检查arraylist中的checkboxlist项目表格c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string[] values = label1.Text.Split(',');

       // foreach (ListView d in checkedListBox1.Items)
       //   {

       for (int x = 0; x < values.Length; x++)
       {
           if (checkedListBox1.Items.ToString() == values[x])
           {
               //checkedListBox1.Items[x].
           }
           //    if (d.ToString() == values[x])
           //    {

           //        label2.Text  = label2.Text + ","+ d;
           //    }
           //}

推荐答案

你应该像这样修改你的代码:

You should modify your code like this:
 for(int i = 0; i < checkedListBox1.Items.Count; i++)
 {
  checkedListBox1.SetItemChecked(i, false);//First uncheck the old value!
  //
  for (int x = 0; x < values.Length; x++)
  {
           if (checkedListBox1.Items[i].ToString() == values[x])
           {
               //Check only if they match! 
               checkedListBox1.SetItemChecked(i, true); 
           }
  }
}


这篇关于如何在窗口中检查arraylist中的checkboxlist项目表格c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆