在线等。。。datagridview选中问题
来源:百度知道 编辑:UC知道 时间:2024/05/02 00:20:22
我想获得datagridview中任意选中的多个单元格的值,进行求和,应该怎么做那?
关键是怎么把值取出来呢?
关键是怎么把值取出来呢?
private void dataGridView1_CellClick(object sender,DataGridViewCellEventArgs e)
{
int sum=0;
foreach (DataGridViewCell dgvc in dataGridView1.SelectedCells)
{
string str = dgvc.Value.ToString();
int i = Convert.ToInt32(str);
sum += i;
}
label1.Text = sum.ToString();
}
VS开发。通过单击单元格任意部分触发事件。
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
int value = (int)dataGridView1.CurrentRow.
Cells["列名"].Value;
//需要转换成数值型
}
在窗体类中声明一个方法,累加取得的值,并返回他们的和。
求和,得用加法
前台用JS实现较麻烦,建议datagridview隐藏控件,事件触发求和
轮询每个选中的单元格取值啊
定位取值应该知道把
datagridview1.Row[].Cell[].Values