C# winform checkboxlist 插件新增和修改实现动态加载多选值

最近研究这个插件浪费了几个小时时间:记录下,分享给有须要的人。记得关注我。this

系统里面记录多选的拼接字符串储存。插件

 

1.新增:3d

           

             //添加checklist到数据中
            string checkedText = string.Empty;orm

            //循环勾选值,只拼接勾选值。  空值不拼接,非空值以逗号隔开。
            for (int i = 0; i < this.ckl_factory.Items.Count; i++)
            {
                if (this.ckl_factory.GetItemChecked(i))
                    checkedText += (String.IsNullOrEmpty(checkedText) ? "" : ",") + this.ckl_factory.GetItemText(this.ckl_factory.Items[i]);
            }blog

2.加载,实现修改界面加载多选值字符串

            

            //服务工厂
            string[] factory_list = edit_supplier.factory_name.Split(',');同步

            //加载checklist数据,加载已选择的数据为checked状态
            string checkedText = string.Empty;
            for (int i = 0; i < factory_list.Length; i++)
            {
                for (int j = 0; j < this.ckl_factory.Items.Count; j++)
                {
                    checkedText = this.ckl_factory.GetItemText(this.ckl_factory.Items[j]);
                    if (factory_list[i]==checkedText)
                    {
                        this.ckl_factory.SetItemChecked(j, true);string

                    }
                }
            }it

3.修改功能跟新增保持一致form

//添加checklist到数据中
            string checkedText = string.Empty;
            for (int i = 0; i < this.ckl_factory.Items.Count; i++)
            {
                if(this.ckl_factory.GetItemChecked(i))
                    checkedText += (String.IsNullOrEmpty(checkedText) ? "" : ",") + this.ckl_factory.GetItemText(this.ckl_factory.Items[i]);
            }

4.同步到gridview

 this.main_form_gridview.SetFocusedRowCellValue("factory_name", edit_supplier.factory_name);

有问题请咨询我。

相关文章
相关标签/搜索