最近研究这个插件浪费了几个小时时间:记录下,分享给有需要的人。记得关注我。
系统里面记录多选的拼接字符串储存。
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);
有问题请咨询我。
来源:oschina
链接:https://my.oschina.net/u/2718657/blog/3074159