Datagridview中的复选框

编程入门 行业动态 更新时间:2024-10-27 13:31:44
本文介绍了Datagridview中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在datagridview中有复选框,当用户选择一些复选框并单击按钮时应该计算价格我该如何实现?

I have checkboxes inside datagridview and when the user selects some checkboxes and click the button the price should be calculated how can i achieve this?

推荐答案

复选框有一个酒店IsChecked属性。您可以使用它来计算您的定价值。 对于那些检查的复选框,您只能为它们执行价格计算。 U可以使用此属性来区分已选中和未选中的复选框。 Checkbox have a property IsChecked property. U can use it to calculate your pricing values. For those check boxes which are check u can perform price calculation for them only. U can use this property to differentiate between check boxes which are checked and which are not.

DataGridView包含DataGridViewRows集合。集合中的每一行都是 DataGridViewRow [ ^ ]。 要获得所选行的总和,您需要遍历行集合: DataGridView contains DataGridViewRows collection. Each row in the collection is DataGridViewRow[^]. To get the total sum of selected rows, you need to iterate through the collection of rows: private void button1_Click(object sender, EventArgs e) { DataGridViewCell dc = null; DataGridViewCheckBoxCell cbx = null; double mySum = 0; string s = string.Empty; foreach (DataGridViewRow dr in dataGridView1.Rows) { dc = dr.Cells[2]; cbx = (DataGridViewCheckBoxCell)dc; if (Convert.ToBoolean(cbx.Value)) { mySum += double.Parse(dr.Cells[0].Value.ToString()); } } s = String.Format("Total sum: {0}", mySum.ToString()); MessageBox.Show(s); } }

更多推荐

Datagridview中的复选框

本文发布于:2023-11-07 09:01:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1566046.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   Datagridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!