vb中的Datagridview计算 [英] Datagridview Computation in vb

查看:86
本文介绍了vb中的Datagridview计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下午好专家,我只是想问一下是否有人知道如何在datagridview中计算totalamount。这就是它的样子:



库存项目说明价格已售数量

4 COke 5 2我将在这个单元格中输入





前三列由SQL查询显示,我想知道如何在PRICE旁边添加一个新列?顺便说一下,价格和销售数量的计算结果将显示在我的文本框中。谢谢!

Good afternoon experts, i just want to ask if anyone knows how to calculate totalamount in datagridview.this is how it looks:

Stocks Item Description Price Sold Quantity
4 COke 5 2 i am the one who will input in this cell


the first three columns are displayed by sql query and i want to know how can i add a new column next to the PRICE?. BTW, the result of the computation of price and sold quantity will be displayed at my textbox. thanks!

推荐答案





1.表结构



ID项目数量费率备注

1可乐20 35没什么

2芯片12 10没什么

3项目1 45 40没有什么

4项目2 60 78没什么

5项目3 40 112没什么



2.让它绑在一个网格,在Rate列旁边添加一个新的列名Total,计算Total = quantity * rate。



3.绑定网格使用datatable为



Hi,

1. Table structure

ID Item Quantity Rate Remark
1 Coke 20 35 Nothing
2 Chips 12 10 Nothing
3 Item1 45 40 Nothing
4 Item2 60 78 Nothing
5 Item3 40 112 Nothing

2. Lets Bind it in a grid, add a new column name Total next to Rate column, calculate Total = quantity * rate.

3. To bind the grid use datatable as

Dim conn As New OleDb.OleDbConnection
Dim da As New OleDb.OleDbDataAdapter
Dim dt As New DataTable

da = New OleDb.OleDbDataAdapter("Select * from Temp", conn)
da.Fill(dt)





3.在Rate列旁边添加一个新列为 -





3. Add a new column next to Rate column as -

Dim cl As New DataColumn
        cl = dt.Columns.Add("Total")
        cl.SetOrdinal(4)





4.计算部分





4. Calculation Part

Dim Rate As Integer
        Dim Quanity As Integer
        Dim Total As Integer

        For i As Integer = 0 To dt.Rows.Count - 1
            Quanity = CInt(dt.Rows(i)(2))
            Rate = CInt(dt.Rows(i)(3))
            Total = Quanity * Rate

            dt.Rows(i)(4) = Total
        Next





5.数据绑定



DataGridView1.DataSource = dt



完成。



5. Data binding

DataGridView1.DataSource = dt

Done.


这篇关于vb中的Datagridview计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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