一、checkedListBoxControl的使用全选

        private void InitDate()
{
CheckedListBoxItem[] itemArr = {
new CheckedListBoxItem("全选",false),
new CheckedListBoxItem("星期一", false),
new CheckedListBoxItem("星期二", false),
new CheckedListBoxItem("星期三", false),
new CheckedListBoxItem("星期四", false),
new CheckedListBoxItem("星期五", true),
new CheckedListBoxItem("星期六", true),
new CheckedListBoxItem("星期日", false)
};
checkedListBoxControl1.Items.AddRange(itemArr);
checkedListBoxControl1.CheckOnClick = true;//控件点击一次就可以选中复选框
checkedListBoxControl1.ItemCheck += CheckedListBoxControl1_ItemCheck; } /// <summary>
/// 监听所有ItemCheck选中状态事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{ //MessageBox.Show(checkedListBoxControl1.GetItemText(e.Index));
//throw new NotImplementedException();
if (checkedListBoxControl1.GetItemText(e.Index) == "全选")
{
if (checkedListBoxControl1.GetItemChecked(0))
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
return;
}
else
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, false);
}
return;//return 解决了 CheckOnClick 检测单击或者双击延迟的问题
} }
else
{
MessageBox.Show("osa");
} }

  

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YKERP.BaseForms;
using YKERP.Business;
using YKERP.Common;
using YKERP.Tools; namespace YKERP.SCM._ReplenishmentMgt.PurchaseOrders
{
public partial class ReplenishmentCycleAddOrEdit : YKBaseForm
{
private string series = null;
//定义委托
public delegate void FuncRefresh();
//定义事件
public event FuncRefresh myRefresh; public ReplenishmentCycleAddOrEdit(Dictionary<string, string> Par)
{
InitializeComponent();
InitData();
if (Par != null)
{
this.series = Par["series"];
Select_Store.ReadOnly = true;
Select_Store.EditValue = Par["sub_unit_num_id"];
Select_Status.EditValue = Par["status_num_id"];
Text_Delivery.Text = Par["delivery_day"];
char[] chs = Par["replenish_weekly_day_flag"].ToCharArray();//分成一个一个的数字
List<string> scoreList = new List<string>();//创建了一个空列表
foreach (var stu in chs)
{
switch (stu)
{
case '1':
scoreList.Add("星期一");
break;
case '2':
scoreList.Add("星期二");
break;
case '3':
scoreList.Add("星期三");
break;
case '4':
scoreList.Add("星期四");
break;
case '5':
scoreList.Add("星期五");
break;
case '6':
scoreList.Add("星期六");
break;
case '7':
scoreList.Add("星期日");
break;
default:
break;
}
} System.String[] str = scoreList.ToArray(); for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{ foreach (string _statisticalTime in str)
{
if (checkedListBoxControl1.GetItemValue(i).ToString() == _statisticalTime)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
} } //CheckedComboBoxEdit 类型的控件
/* if (str != null)
//修改默认选中
foreach (CheckedListBoxItem item in Text_SupplierReplenishment.Properties.Items)
{
foreach (string _statisticalTime in str)
{
if (item.Value.ToString() == _statisticalTime)
{
item.CheckState = CheckState.Checked;
} }
}*/
} } private void InitData()
{
Select_Store.BindData(CommonDicType.门店);
var status_type = new List<object>() {
new { id = "1", name = "未生效" },
new { id = "2", name = "生效" },
};
Select_Status.BindDataTable(YKTool.listToDataTable(status_type));
Select_Status.EditValue = 2; //选择第一项
//自定义数组
//string[] strs = new string[] { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
//添加项
// Text_SupplierReplenishment.Properties.Items.AddRange(strs);
InitDate(); } private void InitDate()
{
CheckedListBoxItem[] itemArr = {
new CheckedListBoxItem("全选",false),
new CheckedListBoxItem("星期一", false),
new CheckedListBoxItem("星期二", false),
new CheckedListBoxItem("星期三", false),
new CheckedListBoxItem("星期四", false),
new CheckedListBoxItem("星期五", true),
new CheckedListBoxItem("星期六", true),
new CheckedListBoxItem("星期日", false)
};
checkedListBoxControl1.Items.AddRange(itemArr);
checkedListBoxControl1.CheckOnClick = true;//控件点击一次就可以选中复选框
checkedListBoxControl1.ItemCheck += CheckedListBoxControl1_ItemCheck;
checkedListBoxControl1.SelectedValueChanged += CheckedListBoxControl1_SelectedValueChanged; ; } private void CheckedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{
//MessageBox.Show(checkedListBoxControl1.GetItemText(e.Index));
//throw new NotImplementedException();
if (checkedListBoxControl1.GetItemText(e.Index) == "全选")
{
if (checkedListBoxControl1.GetItemChecked(0))
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
if (checkedListBoxControl1.SelectedIndex != i)
checkedListBoxControl1.SetItemChecked(i, true);
}
return;
}
else
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
if (checkedListBoxControl1.SelectedIndex != i)
checkedListBoxControl1.SetItemChecked(i, false);
}
return;//return 解决了 CheckOnClick 检测单击或者双击延迟的问题
} }
} private void CheckedListBoxControl1_SelectedValueChanged(object sender, EventArgs e)
{
List<object> objList = checkedListBoxControl1.Items.GetCheckedValues();
//解决失灵的
if (checkedListBoxControl1.GetItemChecked(checkedListBoxControl1.SelectedIndex))
{
checkedListBoxControl1.SetItemCheckState(checkedListBoxControl1.SelectedIndex, CheckState.Checked);
}
else
checkedListBoxControl1.SetItemCheckState(checkedListBoxControl1.SelectedIndex, CheckState.Unchecked); if (objList.Count() == (checkedListBoxControl1.Items.Count - 2))
{
checkedListBoxControl1.SetItemCheckState(0, CheckState.Checked);
//checkedListBoxControl1.SetItemCheckState(checkedListBoxControl1.SelectedIndex, CheckState.Unchecked);
}
if (objList.Count() == 2)
{
checkedListBoxControl1.SetItemCheckState(0, CheckState.Unchecked);
//checkedListBoxControl1.SetItemCheckState(checkedListBoxControl1.SelectedIndex, CheckState.Unchecked);
} } private void btn_AddOrEdit_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(Select_Store.Text))
{
MessageHelper.InfoMsg("请选择门店");
return;
} //MessageBox.Show(Text_SupplierReplenishment.EditValue.ToString());
Dictionary<string, string> data = new Dictionary<string, string>();
var _Store = Select_Store.EditValue?.ToString()?.ToInt() ?? 0;
if (_Store > 0) //门店
data.Add("sub_unit_num_id", _Store.ToString());
data.Add("delivery_day", Text_Delivery.Text);
var _Status = Select_Status.EditValue?.ToString()?.ToInt() ?? 0;
if (_Status > 0) //状态
data.Add("status_num_id", _Status.ToString());
else
{
MessageHelper.InfoMsg("状态不能为空");
return;
}
if (this.series != null)
data.Add("series", this.series); // //List<object> List = Text_SupplierReplenishment.Properties.Items.GetCheckedValues();
List<Object> list = new List<object> { };
string a = null;
for (int i = 0; i < checkedListBoxControl1.Items.Count; i++)
{
if (checkedListBoxControl1.GetItemChecked(i))
{
a = checkedListBoxControl1.GetItemValue(i).ToString();
list.Add(a);
}
} char[] charnumbers = new char[7] { '0', '0', '0', '0', '0', '0', '0' };//定长
foreach (var stu in list)
{
switch (stu)
{
case "星期一":
charnumbers[0] = '1';
break;
case "星期二":
charnumbers[1] = '2';
break;
case "星期三":
charnumbers[2] = '3';
break;
case "星期四":
charnumbers[3] = '4';
break;
case "星期五":
charnumbers[4] = '5';
break;
case "星期六":
charnumbers[5] = '6';
break;
case "星期日":
charnumbers[6] = '7';
break;
default:
break; }
} //MessageBox.Show(res + "--" + res.Count());
data.Add("replenish_weekly_day_flag", string.Join("", charnumbers));
string result = UnitOfWork<DAL>.Resolve.ReplenishmentCycleAddOrEdit(data, out string errors);
if (errors != null)
{
MessageHelper.InfoMsg(errors);
return;
}
if (result != "" || result != null)
{
if (this.series != null)
MessageHelper.InfoMsg("编辑成功");
else
MessageHelper.InfoMsg("添加成功");
this.Close();
myRefresh();
}
else
{
MessageHelper.InfoMsg(errors.ToString());
}
}
}
}

  

原本的

using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using YKERP.BaseForms;
using YKERP.Business;
using YKERP.Common;
using YKERP.Tools; namespace YKERP.SCM._ReplenishmentMgt.PurchaseOrders
{
public partial class ReplenishmentCycleAddOrEdit : YKBaseForm
{
private string series = null;
//定义委托
public delegate void FuncRefresh();
//定义事件
public event FuncRefresh myRefresh; public ReplenishmentCycleAddOrEdit(Dictionary<string, string> Par)
{
InitializeComponent();
InitData();
if (Par != null)
{
this.series = Par["series"];
Select_Store.ReadOnly = true;
Select_Store.EditValue = Par["sub_unit_num_id"];
Select_Status.EditValue = Par["status_num_id"];
Text_Delivery.Text = Par["delivery_day"];
char[] chs = Par["replenish_weekly_day_flag"].ToCharArray();//分成一个一个的数字
List<string> scoreList = new List<string>();//创建了一个空列表
foreach (var stu in chs)
{
switch (stu)
{
case '1':
scoreList.Add("星期一");
break;
case '2':
scoreList.Add("星期二");
break;
case '3':
scoreList.Add("星期三");
break;
case '4':
scoreList.Add("星期四");
break;
case '5':
scoreList.Add("星期五");
break;
case '6':
scoreList.Add("星期六");
break;
case '7':
scoreList.Add("星期日");
break;
default:
break;
}
} System.String[] str = scoreList.ToArray(); for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{ foreach (string _statisticalTime in str)
{
if (checkedListBoxControl1.GetItemValue(i).ToString() == _statisticalTime)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
} } //CheckedComboBoxEdit 类型的控件
/* if (str != null)
//修改默认选中
foreach (CheckedListBoxItem item in Text_SupplierReplenishment.Properties.Items)
{
foreach (string _statisticalTime in str)
{
if (item.Value.ToString() == _statisticalTime)
{
item.CheckState = CheckState.Checked;
} }
}*/
} } private void InitData()
{
Select_Store.BindData(CommonDicType.门店);
var status_type = new List<object>() {
new { id = "1", name = "未生效" },
new { id = "2", name = "生效" },
};
Select_Status.BindDataTable(YKTool.listToDataTable(status_type));
Select_Status.EditValue = 2; //选择第一项
//自定义数组
//string[] strs = new string[] { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };
//添加项
// Text_SupplierReplenishment.Properties.Items.AddRange(strs);
InitDate(); } private void InitDate()
{
CheckedListBoxItem[] itemArr = {
new CheckedListBoxItem("全选",false),
new CheckedListBoxItem("星期一", false),
new CheckedListBoxItem("星期二", false),
new CheckedListBoxItem("星期三", false),
new CheckedListBoxItem("星期四", false),
new CheckedListBoxItem("星期五", true),
new CheckedListBoxItem("星期六", true),
new CheckedListBoxItem("星期日", false)
};
checkedListBoxControl1.Items.AddRange(itemArr);
checkedListBoxControl1.CheckOnClick = true;//控件点击一次就可以选中复选框
checkedListBoxControl1.ItemChecking += CheckedListBoxControl1_ItemChecking; ; } private void CheckedListBoxControl1_ItemChecking(object sender, ItemCheckingEventArgs e)
{
//MessageBox.Show(checkedListBoxControl1.GetItemText(e.Index));
//throw new NotImplementedException();
if (checkedListBoxControl1.GetItemText(e.Index) == "全选")
{
if (checkedListBoxControl1.GetItemChecked(0))
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, false);
}
return;
}
else
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
return;//return 解决了 CheckOnClick 检测单击或者双击延迟的问题
} } if (checkedListBoxControl1.GetItemText(e.Index) != "全选")
{ if (checkedListBoxControl1.SelectedItems.Count() == checkedListBoxControl1.Items.Count)
{
checkedListBoxControl1.SetItemChecked(0, true);
} } } /// <summary>
/// 监听所有ItemCheck选中状态事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CheckedListBoxControl1_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{ //MessageBox.Show(checkedListBoxControl1.GetItemText(e.Index));
//throw new NotImplementedException();
if (checkedListBoxControl1.GetItemText(e.Index) == "全选")
{
if (checkedListBoxControl1.GetItemChecked(0))
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, true);
}
return;
}
else
{
//设置索引为index的项为选中状态
for (int i = 1; i < checkedListBoxControl1.Items.Count; i++)
{
checkedListBoxControl1.SetItemChecked(i, false);
}
return;//return 解决了 CheckOnClick 检测单击或者双击延迟的问题
} }
else
{
MessageBox.Show("osa");
} } private void btn_AddOrEdit_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(Select_Store.Text))
{
MessageHelper.InfoMsg("请选择门店");
return;
} //MessageBox.Show(Text_SupplierReplenishment.EditValue.ToString());
Dictionary<string, string> data = new Dictionary<string, string>();
var _Store = Select_Store.EditValue?.ToString()?.ToInt() ?? 0;
if (_Store > 0) //门店
data.Add("sub_unit_num_id", _Store.ToString());
data.Add("delivery_day", Text_Delivery.Text);
var _Status = Select_Status.EditValue?.ToString()?.ToInt() ?? 0;
if (_Status > 0) //状态
data.Add("status_num_id", _Status.ToString());
else
{
MessageHelper.InfoMsg("状态不能为空");
return;
}
if (this.series != null)
data.Add("series", this.series); // //List<object> List = Text_SupplierReplenishment.Properties.Items.GetCheckedValues();
List<Object> list = new List<object> { };
string a=null;
for (int i = 0; i < checkedListBoxControl1.Items.Count; i++)
{
if (checkedListBoxControl1.GetItemChecked(i))
{
a = checkedListBoxControl1.GetItemValue(i).ToString();
list.Add(a);
}
} char[] charnumbers = new char[7] { '0', '0', '0', '0', '0', '0', '0' };//定长
foreach (var stu in list)
{
switch (stu)
{
case "星期一":
charnumbers[0] = '1';
break;
case "星期二":
charnumbers[1] = '2';
break;
case "星期三":
charnumbers[2] = '3';
break;
case "星期四":
charnumbers[3] = '4';
break;
case "星期五":
charnumbers[4] = '5';
break;
case "星期六":
charnumbers[5] = '6';
break;
case "星期日":
charnumbers[6] = '7';
break;
default:
break; }
} //MessageBox.Show(res + "--" + res.Count());
data.Add("replenish_weekly_day_flag", string.Join("", charnumbers));
string result = UnitOfWork<DAL>.Resolve.ReplenishmentCycleAddOrEdit(data, out string errors);
if (errors!=null)
{
MessageHelper.InfoMsg(errors);
return;
}
if (result != "" || result != null)
{
if (this.series != null)
MessageHelper.InfoMsg("编辑成功");
else
MessageHelper.InfoMsg("添加成功");
this.Close();
myRefresh();
}
else
{
MessageHelper.InfoMsg(errors.ToString());
}
}
}
}

  

三、checkedListBoxControl的更多相关文章

  1. 常用 Gulp 插件汇总 —— 基于 Gulp 的前端集成解决方案(三)

    前两篇文章讨论了 Gulp 的安装部署及基本概念,借助于 Gulp 强大的 插件生态 可以完成很多常见的和不常见的任务.本文主要汇总常用的 Gulp 插件及其基本使用,需要读者对 Gulp 有一个基本 ...

  2. 【原】FMDB源码阅读(三)

    [原]FMDB源码阅读(三) 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 FMDB比较优秀的地方就在于对多线程的处理.所以这一篇主要是研究FMDB的多线程处理的实现.而 ...

  3. Jquery的点击事件,三句代码完成全选事件

    先来看一下Js和Jquery的点击事件 举两个简单的例子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  4. node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理

    一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...

  5. 简谈百度坐标反转至WGS84的三种思路

    文章版权由作者李晓晖和博客园共有,若转载请于明显处标明出处:http://www.cnblogs.com/naaoveGIS/ 1.背景 基于百度地图进行数据展示是目前项目中常见场景,但是因为百度地图 ...

  6. 一起学 Java(三) 集合框架、数据结构、泛型

    一.Java 集合框架 集合框架是一个用来代表和操纵集合的统一架构.所有的集合框架都包含如下内容: 接口:是代表集合的抽象数据类型.接口允许集合独立操纵其代表的细节.在面向对象的语言,接口通常形成一个 ...

  7. 谈谈一些有趣的CSS题目(三)-- 层叠顺序与堆栈上下文知多少

    开本系列,讨论一些有趣的 CSS 题目,抛开实用性而言,一些题目为了拓宽一下解决问题的思路,此外,涉及一些容易忽视的 CSS 细节. 解题不考虑兼容性,题目天马行空,想到什么说什么,如果解题中有你感觉 ...

  8. 如何一步一步用DDD设计一个电商网站(三)—— 初涉核心域

    一.前言 结合我们本次系列的第一篇博文中提到的上下文映射图(传送门:如何一步一步用DDD设计一个电商网站(一)—— 先理解核心概念),得知我们这个电商网站的核心域就是销售子域.因为电子商务是以信息网络 ...

  9. 测试一下StringBuffer和StringBuilder及字面常量拼接三种字符串的效率

    之前一篇里写过字符串常用类的三种方式<java中的字符串相关知识整理>,只不过这个只是分析并不知道他们之间会有多大的区别,或者所谓的StringBuffer能提升多少拼接效率呢?为此写个简 ...

随机推荐

  1. 三、Oracle 查询+where条件

    一.查询1.distinct:查询去除重复的行,是所有的列都重复才满足条件2.列别名:as或者空格 select name as 姓名 from student3.查询字段可以做数学运算,也可以做字符 ...

  2. pytorch例子学习——TRAINING A CLASSIFIER

    参考:https://pytorch.org/tutorials/beginner/blitz/cifar10_tutorial.html#sphx-glr-beginner-blitz-cifar1 ...

  3. 原生js 函数 callee属性

    一.在es5中,函数中有arguments参数,该参数是一个包含函数传入的参数的类数组. <script> function myArrgu(x){ console.log(argumen ...

  4. Java IO(三)——字节流

    一.流类 Java的流式输入/输出是建立在四个抽象类的基础上的:InputStream.OutputStream.Reader.Writer.它们用来创建具体的流式子类.尽管程序通过具体子类执行输入/ ...

  5. 第一次在新西兰组织技术社区活动:Monkeyfest2018

    从3月份登陆到现在,转眼间已经8个月了.在6个月的时候我就想写篇文总结下近期的一些状况,一直拖到现在.因为近期一直在筹备我第一次社区活动——Monkeyfest 2018,占用了比较多的时间.这是一个 ...

  6. js中布尔值为false的六种情况

    下面6种值转化为布尔值时为false,其他转化都为true 1.undefined(未定义,找不到值时出现) 2.null(代表空值) 3.false(布尔值的false,字符串"false ...

  7. hdu 4135 a到b的范围中多少数与n互质(容斥)

    Co-prime 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4135 input The first line on input contains ...

  8. PHP实用代码片段(四)

    1. 删除文件夹内容 function Delete($path) { if (is_dir($path) === true) { $files = array_diff(scandir($path) ...

  9. openstack,docker,mesos,k8s关系

    openstack,docker,mesos,k8s什么关系? - 知乎https://www.zhihu.com/question/62985699 OpenStack + K8S 环境集成测试ht ...

  10. # 【Python3练习题 004】输入某年某月某日,判断这一天是这一年的第几天?

    # [Python练习题 004]输入某年某月某日,判断这一天是这一年的第几天? # 思路:先判断是否为闰年,这关系到 2 月份的天数.# 之后再根据月份值把前几个月的天数累积加起来,最后再加上个“日 ...