[RESOLVED] Changing data in a selected row of a DGV.-VBForums
Results 1 to 3 of 3

Thread: [RESOLVED] Changing data in a selected row of a DGV.

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    415

    Resolved [RESOLVED] Changing data in a selected row of a DGV.

    I have the following DGV in a form

    Name:  DGV1.jpg
Views: 177
Size:  5.3 KB

    As can be seen, the DGV consists of two approvers. The empty cells at the end of each row would be where a signature would be displayed if either of the approvers had signed-off.

    I have a double click event that can do one of two things, based on one of two button click events. The first is to add another approver to the list, which works just fine. The second is to remove one of the approvers from the list, which currently looks like this:

    Code:
                        'Remove Approver from list
                        CType(lnkChangeApproveBindingSource.Current, DataRowView).Item("strSignature") = CStr("Removed by Change Admin, " + glbstrLogin) + " " + CStr(DateAndTime.Now)
                        CType(lnkChangeApproveBindingSource.Current, DataRowView).Item("blnRemoved") = True
                        glbstrAuditMessage = CType(lnkChangeApproveBindingSource.Current, DataRowView).Item("strFullName") + " was removed from the Approver list."
                        Me.Validate()
                        lnkChangeApproveBindingSource.EndEdit()
                        LnkChangeApproveTableAdapter.Update(Me._MasterBase5_0DataSet)
                        LnkChangeApproveTableAdapter.FillByChangeID(Me._MasterBase5_0DataSet.lnkChangeApprove, glbintChangeID)
                        dgvSignList.Enabled = False
                        'Audit Trail
                        AuditDocProcess()
    When I double click in a cell on a row, an approver is indeed removed (the record is not actually removed, but values are changed in the record). However it is always the one at the top of the list. I had thought that .Current would index to the desired row, but obviously, it does not. I attempted a couple of other approaches, like:

    Code:
    CStr(dgvSignList.Rows(e.RowIndex).Cells("strSignature").Value.ToString()) = CStr("Removed by Change Admin, " + glbstrLogin + " " + CStr(DateAndTime.Now))
    The expression to the left of the = sign will not work using .Value (even after reading the reasons for this I still do not understand why). It will only work when it is on the right side of the = sign.

    I do have a method that will work for this, but I would prefer to use a method that places a value(s) directly into desired row.

    Can anyone steer me in the right direction for this? I am still trying a few other things, but at this point it is nothing more than looking up something I do not entirely understand and just trying it out.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    39,737

    Re: Changing data in a selected row of a DGV.

    Quote Originally Posted by gwboolean View Post
    I attempted a couple of other approaches, like:

    Code:
    CStr(dgvSignList.Rows(e.RowIndex).Cells("strSignature").Value.ToString()) = CStr("Removed by Change Admin, " + glbstrLogin + " " + CStr(DateAndTime.Now))
    The expression to the left of the = sign will not work using .Value (even after reading the reasons for this I still do not understand why). It will only work when it is on the right side of the = sign.
    You don't need the CStr() on the left, because you are already using .ToString (so the CStr is converting a String to a String, which is the same as doing nothing).

    You also don't need the .ToString(), because you only do that while reading a value, and you want to write a value.

    There is also no need for the CStr just after the equals sign, because the values inside it are all strings already.

    As such, that line of code should have been:
    Code:
    dgvSignList.Rows(e.RowIndex).Cells("strSignature").Value = "Removed by Change Admin, " & glbstrLogin & " " & CStr(DateAndTime.Now)
    (using & to join strings is far safer than using + , which has problems in some circumstances)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    415

    Re: Changing data in a selected row of a DGV.

    Got it. And that works quite well. Obviously, I was going way overboard and using a lot of superfluous crap. Just proves that you can screw the pooch by the numbers when you are doing something you do not fully understand. What really threw me off was that when I would look at the error for this it always referred to the .Value instead of the .ToString().

    Thanks.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width