【发布时间】:2015-03-18 21:02:34
【问题描述】:
我正在尝试创建一个 dataGridView,它有 2 列,第 1 列包含名称,第 2 列包含数字,工作正常。
我现在想允许用户使用键盘或鼠标选择单行或多行,这应该会根据所选行自动汇总数字列。
到目前为止,我有以下几点:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (dataGridView1.SelectedCells.Count > 0)
{
int selectedrowindex = dataGridView1.SelectedCells[0].RowIndex;
DataGridViewRow selectedRow = dataGridView1.Rows[selectedrowindex];
string a = Convert.ToString(selectedRow.Cells[0].Value);
}
}
string a 最终将在表单的标签中显示总数。
但这似乎是做我想要实现的目标的错误方法。有什么建议吗?
【问题讨论】:
-
您的代码只显示当前单元格?您想要一个所选数字的总和?
标签: c# .net visual-studio-2013 .net-3.5