473,395 Members | 2,796 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Updating Datagridview Value

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.

7 1221
Rabbit
12,516 Expert Mod 8TB
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
Robin25
22
Thank you again Mr.Rabbit.. . and now i know what should i fix . .
Apr 8 '14 #3
Robin25
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
Robin25
22
Any sample code or something else that describe how to that?
Apr 8 '14 #5
Rabbit
12,516 Expert Mod 8TB
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
Robin25
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
12,516 Expert Mod 8TB
No problem, good luck with the rest of your project.
Apr 10 '14 #8

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

Similar topics

2
by: MisConFit8 | last post by:
My question is this - is it possible to set a standard value in the web.config file and change it later based on conditions? Why, you might ask? I am building a web based application for...
2
by: Alani | last post by:
Hello All, I'm a new ASP.NET programmer and I want to create a custom control consist of two properties (Number1) and (Number2) and both of them are integers and default value = 0, now I'm...
7
by: Arne Beruldsen | last post by:
When I go to update my datagridview...I get this error Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information. ...
3
by: Looch | last post by:
Hi all, Here's the code I'm using: Dim sqlCnn As New SqlConnection(cnn) Dim sqlCmd As New SqlCommand("Update AMS.dbo.Call_Log Set Status = @status, UPSTrack = @ups where TicketNumberActual =...
2
by: berry | last post by:
Hi all... I want to delete the data that over 5years. But my code has such error: "vb6 error: Row cannot be located for updating. Some value may have been changed since it was last read." And...
4
by: directory | last post by:
hey guys, I've got a weird one for ya....i have a form which takes user input in the form of textbox's etc. It then grabs some details from a file and updates some of the labels with some info...
0
by: Pascal | last post by:
Hello I began with vbnet and databinding. I created a database containing a table access Students. In a form frmListEleves I slipped and deposited the table in question and a datagridview was...
4
by: Edwin Velez | last post by:
http://msdn.microsoft.com/en-us/library/806sc8c5.aspx The URL above gives sample code for use within a Console Application. What I would like to do is use this code within a Windows Form. That...
1
by: pv003220 | last post by:
Hi Guys, I wonder if anybody could help me with a bit of VB coding. Im after some code so that I can select a value from a table, and then be able to update that value. My aim is to be able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.