获得CheckListBox的结果。

来源:互联网 发布:linux自定义命令 编辑:程序博客网 时间:2024/05/21 09:11
 

        /// <summary>
        /// 获得checkListBox被选中的结果
        /// </summary>
        /// <returns></returns>
        private bool[] checkListBox1_Result()
        {
            try
            {


            if (checkedListBox1.Items.Count == 0)
                return null;
            int j = checkedListBox1.Items.Count;
            int i = checkedListBox1.CheckedItems.Count;
            bool[] res = new bool[j];
     
            int k = 0;
                while (k < j)
                {
                    if (checkedListBox1.GetItemChecked(k))
                    {
                        res[k] = true;
                    }
                    else
                    {
                        res[k] = false;
                    }
                    k++;
                }

                return res;
            }
            catch
            {
                return null;
            }
        }

 

 

//绑定数据源

  private void checkedListBox1_Refresh(string recipename)
        {
                if (recipename == null || recipename == "")
                return;

            checkedListBox1.Items.Clear();
            DataBaseManage dbtest = new DataBaseManage();
            string[] Trajnametype = null;
            if(( Trajnametype = dbtest.GetAllTrajnametype(recipename))==null)
            {
                return;
            }
            int i = 0;
            while (i < Trajnametype.Length)
            {
                if (Trajnametype[i] == null)
                {
                    i++;
                    continue;
                }
                else
                {
                    checkedListBox1.Items.Add(Trajnametype[i]);
                    i++;
                }
            }

        }