在datagridview中添加并添加两行的值 [英] Marge and add two row's value in datagridview

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

问题描述

我在vb2010中有一个datagridview,并且其中有一些coman值.我想添加这些值并将其作为一个单行

我有一个前.我有一个看起来像的人:

名称数量单位

土豆5公斤
poteto 10克
beance 10克
土豆1公斤


这里的名字数量和单位是三个可伦.
但是我希望它的必必看起来像

名称数量单位

土豆6.10公斤
beance 10克

任何人都请提供一个前.或代码,谢谢
我正在使用vb2010和sql2008

i have a datagridview in vb2010 and have some coman value in it . i want to add those value and make it as a one singal row

i have a ex. i have a view who looks like :

name quantity unit

poteto 5 kg
poteto 10 gm
beance 10 gm
poteto 1 kg


here name quantiy and unit are three colams
But i want that its must bi looks like

name quantity unit

poteto 6.10 kg
beance 10 gm

anyone please provide a ex. or code , thanks
i am using vb2010 and sql2008

推荐答案

您可以在查询结果本身中进行串联.
You can do a concatenation in your query results itself.


我是为此尝试代码
但这给了我一些错误
你能嚼它吗..
i am trying a code for this
but it give me some error
can u cheak it plz ..
Private Sub calculateIngradient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      Dim a, b As String
      For i = 0 To DataGridView1.RowCount - 1
          a = DataGridView1.Rows(i).Cells(0).Value
          For j = 0 To DataGridView1.RowCount - 1
              b = DataGridView1.Rows(j).Cells(0).Value
              If a = b Then
                  DataGridView1.Rows(i).Cells(1).Value = DataGridView1.Rows(i).Cells(1).Value + DataGridView1.Rows(j).Cells(1).Value
                  DataGridView1.Rows(i).Cells(2).Value = DataGridView1.Rows(i).Cells(2).Value & " / " & DataGridView1.Rows(j).Cells(2).Value
                  DataGridView1.Rows.Remove(DataGridView1.Rows(j))

              End If
          Next
      Next
  End Sub


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

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