Results 1 to 4 of 4

Thread: Moving from one DGV to another

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2014
    Posts
    71

    Moving from one DGV to another

    Hi. I was wondering if anyone could help me with this... I have two DGViews. One represents devices with certain identification info while the second represents technical info about whatever item is selected in the 1st dgv. If the user changes info on the 2nd dgv and returns to a different row in the first dgv, I have a msgbox asking if they want to save the changes. The problem I having is no matter what the user selects in the msgbox, after their selection is made, the row doesn't update however, if I remove the msgbox completely it does update to the new row.

    Code:
        Private Sub AvailableDevices_dgv_RowEnter(sender As Object, e As DataGridViewCellEventArgs) Handles AvailableDevices_dgv.RowEnter
            CurrentRow_tb.Text = e.RowIndex
            RowJustEntered = e.RowIndex ' This is the number Ports_dgv goes by
    
            If CellChanged = True Then
                If MessageBox.Show("Save changes to this device?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
                    CellChanged = False
                    ' change values back to originals
                    Exit Sub
                End If
                ' Save values code goes here
            End If
    
            OrigManufacturer = AvailableDevices_dgv.Rows(e.RowIndex).Cells(0).Value
            OrigModel = AvailableDevices_dgv.Rows(e.RowIndex).Cells(1).Value
            OrigMnemonic = AvailableDevices_dgv.Rows(e.RowIndex).Cells(2).Value
            OrigWebAdr = AvailableDevices_dgv.Rows(e.RowIndex).Cells(3).Value
            GetPorts()
        End Sub

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Moving from one DGV to another

    Looking at your code, if the user selects yes then the code inside the "If" statement will not be executed. So I don't see how removing that structure would affect anything. Try putting some break points in the sub so you can follow the path the code takes. You could also put the code inside a Try/Catch just in case there some type of silent error.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2014
    Posts
    71

    Re: Moving from one DGV to another

    Thanks for the reply wes but the fact of the matter is regardless of whether the user answers yes or no to the save messagebox, the 1st dgv row is not updated. That is to say if the user is on row 5 in dgv1 (AvailableDevices_dgv) then makes a change in dgv2 (Ports_dgv) and when completed, they click back on dgv1 but in a different row. The new row is not selected.

    Also, what's interesting is that even though the CellChanged flag is reset to false. If the user selects a new row after the row is not updated, the next new row click fires the The Save Changes dialog again.
    Last edited by x60hz; Jan 28th, 2015 at 04:22 PM.

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,195

    Re: Moving from one DGV to another

    You said in your first post that if you removed the message box from the code, your update worked. Which doesn't make any sense. If you answer yes to the message the code will not execute. So either the code you posted doesn't match the code your using or your path of execution is not what you thought. Thats why I suggested putting break points and stepping thru the code just to be sure whats actually happening. Have you tried that, if so what executes when you answer Yes to the messagebox.

Posting Permissions

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



Click Here to Expand Forum to Full Width