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

旧时模样 提交于 2019-11-30 13:54:46

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

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

 

1.新增:

           

             //添加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]);
            }

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);

                    }
                }
            }

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

//添加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);

有问题请咨询我。

 

 

 

 

 

 

 

 

 

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!