Updating Datagridview Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Robin25
    New Member
    • Apr 2014
    • 22

    Updating Datagridview Value

    Code:
     If grid_selected_item.Rows.Count = 0 Then
    
                        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)
    
                    Else
    
    
    
    
                        For ichk As Integer = 0 To grid_selected_item.Rows.Count - 1
    
                            If txt_article_name.Text <> grid_selected_item.Rows(ichk).Cells(0).Value Then
                                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)
                            Else
                                If txt_article_name.Text = grid_selected_item.Rows(ichk).Cells(0).Value Then
    
                                    Dim new_gross As Decimal
                                    Dim new_net As Decimal
                                    Dim new_dis As Decimal
                                    Dim dis_val As Decimal
                                    grid_selected_item.Rows(ichk).Cells(3).Value = grid_selected_item.Rows(ichk).Cells(3).Value + Val(txt_qty.Text)
    
                                    new_gross = grid_selected_item.Rows(ichk).Cells(3).Value * grid_selected_item.Rows(ichk).Cells(4).Value
                                    new_dis = "." + grid_selected_item.Rows(ichk).Cells(5).Value
                                    dis_val = new_dis * new_gross
                                    new_net = new_gross - dis_val
    
    
    
                                    grid_selected_item.Rows(ichk).Cells(6).Value = new_gross
                                    grid_selected_item.Rows(ichk).Cells(7).Value = new_net
    
    
    
                                End If
    
    
                            End If
    
    
    
    
    
    
    
    
                        Next
    
                    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)
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    It's because you are looping through the rows and adding a row each time the article name doesn't match the grid.

    Comment

    • Robin25
      New Member
      • Apr 2014
      • 22

      #3
      Thank you again Mr.Rabbit.. . and now i know what should i fix . .

      Comment

      • Robin25
        New Member
        • Apr 2014
        • 22

        #4
        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

        Comment

        • Robin25
          New Member
          • Apr 2014
          • 22

          #5
          Any sample code or something else that describe how to that?
          Last edited by Robin25; Apr 8 '14, 05:32 AM. Reason: Double Post

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

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

            Comment

            • Robin25
              New Member
              • Apr 2014
              • 22

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

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                No problem, good luck with the rest of your project.

                Comment

                Working...