我想要做这样一种效果:
DataGridView绑定了一个只有一列的DataTable,该列的类型为int;
而DataGridView显示的时候显示两列,一列是DataTable有的内容,另一列中是CheckBox控件;
界面上还有一个按钮用于求和;
求和的方法是有选择的求和,只有CheckBox被勾选的那行中的数据才会被计算进来。
希望能提供一种比较详细的方案。
DataGridView绑定了一个只有一列的DataTable,该列的类型为int;
而DataGridView显示的时候显示两列,一列是DataTable有的内容,另一列中是CheckBox控件;
界面上还有一个按钮用于求和;
求和的方法是有选择的求和,只有CheckBox被勾选的那行中的数据才会被计算进来。
希望能提供一种比较详细的方案。
解决方案 »
- MsChart效果
- 求助:用UDP协议读取传感器信息
- C#.net里,可以调用Word里的一些窗体吗?
- 能否能够查询我所输入的数据呢?
- 如何编程记事本程序?
- 用GDI+放大图像,采用的插值方法为InterpolationModeNearestNeighbor,发现最左侧和最右侧的图像有偏移,有谁遇到过这个情况?
- 刚刚上路请教:怎么才能把不同的数据写入同一个文件里呢?
- vs2005中数据库的问题
- 请问有谁做过数据动态显示的功能?(效果如“Windows 任务管理器”的CPU使用记录)
- 怎么取DataSet中的数据来着?
- 求教 将截断字符串或二进制数据。语句以终止.
- 请教C#读取网页信息,中文显示乱码的问题。附有代码
<ItemTemplate>
……
<asp:checkBox id="chk" runat="server" />
</itemtemplate>
你直接取选中checkbox行的值,然后求和就可以了。
'动态添加CheckBox列
Dim cel As New DataColumn("确认", System.Type.GetType("System.Boolean"))
dst.Tables(0).Columns.Add(cel)
cel.SetOrdinal(1)
DataGridView.datasource=dst.Tables(0)
Dim dblSumQty as Double = 0For i As Integer = 0 To DataGridView.Rows.Count - 1
If DataGridView.Rows(i).Cells(1).FormattedValue = True Then '打勾
If Not IsDBNull(DataGridView.Rows(i).Cells("Qty").Value) Then
if isNumeric(DataGridView.Rows(i).Cells("Qty").Value) then
dblSumQty = dblSumQty + Cdbl(DataGridView.Rows(i).Cells("Qty").Value)
end if
End If
End If
Next
不过既然是winform, 那么界面应该直接让用户框选,一个个点复选框多累啊.
{
if (grdDetail[0, i].Value == True)
{
sum = sum + Decimal.Parse(grdDetail[1, i].Value.ToString());
}
}
用代码怎么设?
DataGridViewColumn col = new DataGridViewCheckBoxColumn();
this.dataGridView1.Columns.Add(col);
DataGridViewColumn col = new DataGridViewCheckBoxColumn();
this.dataGridView1.Columns.RemoveAt(0);
this.dataGridView1.Columns.Insert(0, col);
所以想问一下,如何对这个checkbox列进行操作
{
if (grdDetail[0, i].Value == True)
{
sum = sum + Decimal.Parse(grdDetail[1, i].Value.ToString());
}
}
代码中
if (grdDetail[0, i].Value == True)
编译不能通过,提示
错误 1 运算符“==”无法应用于“object”和“bool”类型的操作数