一、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. linux命令之df

    功能:查看文件系统的磁盘空间使用情况 常用选项: -a 包含虚拟文件系统 -h 可易读单位显示 -i 显示 inode 信息而非块使用量 -k 1K 块的数量 -t 只显示指定文件系统为指定类型的信息 ...

  2. 学习! ! ! Study! ! !

    我们是年轻人,钱不重要,前途才重要,干嘛着急挣钱啊.  学习!!!  study!!!

  3. P4550 收集邮票-洛谷luogu

    传送门 题目描述 有n种不同的邮票,皮皮想收集所有种类的邮票.唯一的收集方法是到同学凡凡那里购买,每次只能买一张,并且买到的邮票究竟是n种邮票中的哪一种是等概率的,概率均为1/n.但是由于凡凡也很喜欢 ...

  4. jquery()后续版本中,live()取消后使用on()实现功能写法

    今天做项目想用live()功能,写完打开浏览器发现报错 然后查了查发现自己用的是jquery是jquery-2.1.1.min.js,而jquery早就取消了live()方法,在后续版本里都已经没有使 ...

  5. 【原创】自己动手写一个能操作redis的客户端

    引言 redis大家在项目中经常会使用到.官网也提供了多语言的客户端供大家操作redis,如下图所示 但是,大家有思考过,这些语言操作redis背后的原理么?其实,某些大神会说 只要按照redis的协 ...

  6. Makefile有三个非常有用的变量。分别是$@,$^,$

    原文地址:https://blog.csdn.net/u013774102/article/details/79043559 假设我们有下面这样的一个程序,源代码如下: /* main.c */ #i ...

  7. Python-正则复习-56

    # 正则表达式# 字符组 [字符]# 元字符 # \w \d \s # \W \D \S # . 除了换行符以外的任意字符 # \n \t # \b # ^ $ 匹配字符串的开始和结束 # () 分组 ...

  8. Contest1692 - 2019寒假集训第三十一场 UPC 11075 Problem D 小P的国际象棋

    非常简单的单点修改+区间加+区间查询.我用的是最近刚学的区间修改版本树状数组.  直接维护即可,注意修改后的单点值已经不是a[i],或者b[i],要通过区间查询求单点.不然是错的. 区间修改版本树状数 ...

  9. Atcoder F - LCS (DP-最长公共子序列,输出字符串)

    F - LCS Time Limit: 2 sec / Memory Limit: 1024 MB Score : 100100 points Problem Statement You are gi ...

  10. ubuntu中更改apache默认目录的方法

    如上,在这两个文件中,我都改为/home/www 及/home/www/html