本文介绍了如何使用Windows vb.net汇总Datagridview的列值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个datagridview,其中包含金额"列.
我也有一个文本框
我希望金额"列的总和出现在文本框中
我尝试了以下方法:

VB代码:
总暗淡为整数

对于每行,作为DataGridView1.Rows中的DataGridViewRow
总计+ = row.Cells(amount).Value
下一个

txtmon.Text =总计

我收到消息无法找到列金额".
参数名称:ColumnName

你们知道我在做什么错吗?
在此先感谢
Sucharitha

Hi,
I have a datagridview that contains the column "Amount".
I also have a textbox
I want the sum of the column "amount" to appear in the textbox
I have tried the following:

VB Code:
Dim total As Integer

For Each row As DataGridViewRow In DataGridView1.Rows
total += row.Cells(amount).Value
Next

txtmon.Text = total

I get the message "Cant find column "amount".
Parametername: ColumnName

Do you guys have an idea what i am doing wrong????

Thanks in advance
Sucharitha

推荐答案

total += row.Cells(amount).Value


更正此行

如果您的列名称为金额",则应将其用双引号引起来


correct this line

if your column name is ''amount'' then you should write it in double quotes

total += row.Cells("amount").Value



或者您可以按数字访问金额"列,从0开始开始对列进行计数

例如.



or you can access column ''amount'' by number start counting columns from 0 to onwards

eg.

ColumnName
name   address   amount
ColumnIndex
0      1         2




在这里,对于金额" columnName,column-index为2

因此,我们可以将其编写如下




here, for ''amount'' columnName, column-index is 2

so, we can write it as below

total += row.Cells(2).Value 



祝您编码愉快!
:)



Happy Coding!
:)


total += row.Cells("Amount").Value


或者您可以使用变量``amount'':


Or you can use variable ''amount'':

Dim amount As String="Amount"
For Each row As DataGridViewRow In DataGridView1.Rows
total += row.Cells(amount).Value
Next


这篇关于如何使用Windows vb.net汇总Datagridview的列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 05:39