By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

Updating Datagridview Value

P: 22
Expand|Select|Wrap|Line Numbers
  1.  If grid_selected_item.Rows.Count = 0 Then
  2.  
  3.                     grid_selected_item.Rows.Add(txt_article_name.Text, txt_color.Text, txt_size.Text, txt_qty.Text, lbl_selling.Text, txt_discount.Text, GROSS, Total_net, cur_qty, lbl_art_no.Text)
  4.  
  5.                 Else
  6.  
  7.  
  8.  
  9.  
  10.                     For ichk As Integer = 0 To grid_selected_item.Rows.Count - 1
  11.  
  12.                         If txt_article_name.Text <> grid_selected_item.Rows(ichk).Cells(0).Value Then
  13.                             grid_selected_item.Rows.Add(txt_article_name.Text, txt_color.Text, txt_size.Text, txt_qty.Text, lbl_selling.Text, txt_discount.Text, GROSS, Total_net, cur_qty, lbl_art_no.Text)
  14.                         Else
  15.                             If txt_article_name.Text = grid_selected_item.Rows(ichk).Cells(0).Value Then
  16.  
  17.                                 Dim new_gross As Decimal
  18.                                 Dim new_net As Decimal
  19.                                 Dim new_dis As Decimal
  20.                                 Dim dis_val As Decimal
  21.                                 grid_selected_item.Rows(ichk).Cells(3).Value = grid_selected_item.Rows(ichk).Cells(3).Value + Val(txt_qty.Text)
  22.  
  23.                                 new_gross = grid_selected_item.Rows(ichk).Cells(3).Value * grid_selected_item.Rows(ichk).Cells(4).Value
  24.                                 new_dis = "." + grid_selected_item.Rows(ichk).Cells(5).Value
  25.                                 dis_val = new_dis * new_gross
  26.                                 new_net = new_gross - dis_val
  27.  
  28.  
  29.  
  30.                                 grid_selected_item.Rows(ichk).Cells(6).Value = new_gross
  31.                                 grid_selected_item.Rows(ichk).Cells(7).Value = new_net
  32.  
  33.  
  34.  
  35.                             End If
  36.  
  37.  
  38.                         End If
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.                     Next
  48.  
  49.                 End If

in 1st row it's working and also in 2nd, but in 3rd rows , the data that i enter are getting multiply by the current row . . (Sorry for worse english)
Apr 7 '14 #1

✓ answered by Rabbit

You need to add the row outside of the loop and only if the loop says that the row doesn't already exist.

Share this Question
Share on Google+
7 Replies


Rabbit
Expert Mod 10K+
P: 12,349
It's because you are looping through the rows and adding a row each time the article name doesn't match the grid.
Apr 7 '14 #2

P: 22
Thank you again Mr.Rabbit.. . and now i know what should i fix . .
Apr 8 '14 #3

P: 22
in hour ago. . .
i try to work out my code but it seem's . . .
if i post my whole code here it's gonna be burst on this page,
any sample code or logic how to update value in unbound datagridview
Apr 8 '14 #4

P: 22
Any sample code or something else that describe how to that?
Apr 8 '14 #5

Rabbit
Expert Mod 10K+
P: 12,349
You need to add the row outside of the loop and only if the loop says that the row doesn't already exist.
Apr 8 '14 #6

P: 22
I revise my whole coding for that, and follow your guide, then. . it's work. Thanks a lot Sir
Apr 10 '14 #7

Rabbit
Expert Mod 10K+
P: 12,349
No problem, good luck with the rest of your project.
Apr 10 '14 #8

Post your reply

Sign in to post your reply or Sign up for a free account.