none
Copy column to another column in a datagridview RRS feed

  • Question

  • guys help me on how to update a column

    i have a data here

    price        paid         balance

    3              0               12

    4              0               12

    5              0               12

    what i want to do is to update the "paid" column and after clicking a button my DGV will become like this

    price        paid         balance

    3              3               0

    4              4               0

    5              5               0

    my data in not from database
    • Edited by no[one] Tuesday, February 5, 2019 8:28 PM
    Tuesday, February 5, 2019 8:27 PM

Answers

  • Hi

    Here is somer code that does exactly as you ask. However, I suspect that what you stated in your question is NOT actually what you want. If Iam correct then you will need to explain some more.

    ' Form1 with blank DataGridView1,
    ' Button1
    Option Strict On
    Option Explicit On
    Public Class Form1
      Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        With DataGridView1
          .Columns.Add("Price", "Price")
          .Columns.Add("Paid", "Paid")
          .Columns.Add("Balance", "Balance")
    
          .Rows.Add(3, 0, 12)
          .Rows.Add(4, 0, 12)
          .Rows.Add(5, 0, 12)
        End With
    
      End Sub
      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        For Each r As DataGridViewRow In DataGridView1.Rows
          If Not r.Index = DataGridView1.NewRowIndex Then
            With r
              .Cells("Paid").Value = .Cells("Price").Value
              .Cells("Balance").Value = 0
            End With
          End If
        Next
      End Sub
    End Class
    


    Regards Les, Livingston, Scotland

    • Marked as answer by no[one] Monday, February 18, 2019 1:57 PM
    Tuesday, February 5, 2019 9:25 PM