添加datagrid列值并在文本框中显示 [英] add datagrid column value and display in textbox

查看:93
本文介绍了添加datagrid列值并在文本框中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我在网格中有一列金额。

用户可以输入多个项目。



所以我必须在文本框中显示总金额。



请告诉我怎么做...



我写了这个但没有按预期得到



  Dim  totalSum  As  整数 
Dim ds As DataSet
< span class =code-keyword>对于 i 作为 整数 = 0 ds.Tables( 0 )。Rows.Count - 1
totalSum + = ds.Tables( 15 )。行(i).Item ( TotalAmt
下一步

txtTotalAmount.Text = totalSum.ToString









谢谢

解决方案

1。声明一个变量来保存总金额。

2.遍历网格并将每行的金额添加到总变量中。

3.将文本框的文本属性设置为变量,格式化为您想要的格式。



如果您不确定如何做这些事情,首先尝试在谷歌上搜索帮助。获得一些代码后,如果仍然无效,请点击改善问题链接并将代码添加到您的问题中。然后我们可以帮你修复它。



希望这会有所帮助。


我使用下面的代码



  Dim  TOTAL  As  < span class =code-keyword> Double  =  0  
对于 < span class =code-keyword>每个行作为 DataRow dTable.Rows
TOTAL + = Double .Parse(row( TotalAmt)。ToString())
下一步
txtTotalAmount.Text = TOTAL


Hi all

I have a column for amount in the grid.
user can enter multiple items.

so i have to show them the total amount in a text box.

Please tell me how to do that..

I wrote this but not getting as expected

Dim totalSum As Integer
      Dim ds As New DataSet
      For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
          totalSum += ds.Tables(15).Rows(i).Item("TotalAmt")
      Next

      txtTotalAmount.Text = totalSum.ToString





Thank you

解决方案

1. Declare a variable to hold the total amount.
2. Loop through the grid and add each row's amount to the total variable.
3. Set the textbox's text property to the variable, formatted as you desire.

If you are not sure how to do these things, try searching for help on google first. Once you have some code, if it is still not working, please click the Improve question link and add your code to your question. Then we can help you fix it.

Hope this helps.


I have used below code

Dim TOTAL As Double = 0
     For Each row As DataRow In dTable.Rows
         TOTAL += Double.Parse(row("TotalAmt").ToString())
     Next
     txtTotalAmount.Text = TOTAL


这篇关于添加datagrid列值并在文本框中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆