Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 5-Aug-12 19:06pm
v2
Comments
AshishChaudha 6-Aug-12 1:41am    
What you have tried so far...
Vipin Sharma 6-Aug-12 4:32am    
please have a look , i use this code for add row's value bt it don't work properly

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

You can do a concatenation in your query results itself.
 
Share this answer
 
Comments
Vipin Sharma 6-Aug-12 4:19am    
i am trying this code for add the values of datagrid view
but it give some error can u solve that

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
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900