如何取DataGridViewCheckBoxCell值
来源:互联网 发布:手机淘宝扫一扫 编辑:程序博客网 时间:2024/04/30 06:34
今到遇到这样的应用,主档datagridview要通过点选Checkbox列,实时计算Checkbox=true的所有明细金额合计,
网上有提到使用EditedFormattedValue和FormattedValue的值的判断,但使用起来还是麻烦,要做判断,于是想到用点选后马上结束编辑状态,结果还变好用的,上代码,以备后用:
/// <summary> /// 选择内容 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { //取当前datagridview DataGridView dgv = (DataGridView)sender; //这句很关键,结束编辑状态 dgv.EndEdit(); //选择列判断 if (dgv.Columns[e.ColumnIndex].DataPropertyName.ToLower() == "selcol") { string idlist = "", pk = "id"; DataGridViewCheckBoxCell dgchk=null; foreach (DataGridViewRow item in dgv.Rows) { dgchk = (DataGridViewCheckBoxCell)item.Cells["selcol"]; //判断选择列是否已被选 if ((bool)item.Cells["selcol"].Value) { idlist += idlist == "" ? item.Cells[pk].Value.ToString() : "," + item.Cells[pk].Value.ToString(); } } //计算选择的明细金额 float selprice = Util.ShowVoiceMoney(idlist,pk, "iMoney", "PU_arrivalVouchs"); lb3.Text = string.Format("已选金额:{0}", selprice.ToString("F2")); lb_rate.Text = string.Format("已选金额比例:{0}%", AllPrice == 0 ? "0.00" : (selprice / AllPrice * 100).ToString("F2")); } }
0 0
- 如何取DataGridViewCheckBoxCell值
- 如何判断DataGridViewCheckBoxCell被选中
- Datagridview DataGridViewCheckBoxCell
- this如何取值?
- 如何在winform的 DataGridView 中捕捉 CheckBox ( DataGridViewCheckBoxCell ) 列的状态改变
- 如何在winform的 DataGridView 中捕捉 CheckBox ( DataGridViewCheckBoxCell ) 列的状态改变
- 如何在winform的 DataGridView 中捕捉 CheckBox ( DataGridViewCheckBoxCell ) 列的状态改变
- 如何在winform的 DataGridView 中捕捉 CheckBox ( DataGridViewCheckBoxCell ) 列的状态改变
- 如何在winform的 DataGridView 中捕捉 CheckBox ( DataGridViewCheckBoxCell ) 列的状态改变 .
- 如何在winform的 DataGridView 中捕捉 CheckBox ( DataGridViewCheckBoxCell ) 列的状态改变
- 不回车如何取值
- SimpleXMLElement Object如何取值
- DataGridView - DataGridViewCheckBoxCell的使用
- DataGridView - DataGridViewCheckBoxCell的使用
- 在.NET中如何取单个值
- Android动态生成控件如何取值
- 如何取LR web_reg_sava_param的值
- dedecms cn_substr如何反向取值
- [LeetCode] 4 Median of Two Sorted Arrays
- Android中Application类用法
- Search a 2D Matrix
- linux用户管理,运行级别
- Ubuntu在VirtualBox下的磁盘空间扩展
- 如何取DataGridViewCheckBoxCell值
- 从view角度看dialog 和 toast
- options for pipe mode
- 快速查找长度未知的单链表的中间结点
- 不使用*、/、+、-、%操作符求一个数的1/3[算法]
- 文章标题
- 线程池的简单实现
- Single Number II
- 在Android项目中(百度地图),报错:key验证出错,请在AndroidManifest.xml文件中检查key设置