Well I have sort of found a workaround this problem am not sure if it is one of the better ones so would like to know any better way
Dim gFlag As Boolean = False
Function MakeChoice(ByVal Name As String, ByVal i As Integer)
Dim flag As Boolean
Dim C1, C2 As MsgBoxResult
Dim msg As String = "Select a row and press Ok to add a value to that row " & _
"Or Press cancel to Add a New Row"
'Displays and Records Users Input
C1 = MessageBox.Show(msg, Name, MessageBoxButtons.OKCancel)
Select Case C1
'If user wants to choose one of the rows in datagridview
Case MsgBoxResult.Ok
flag = True
'Scrolls to the row with closest match
dgv1.FirstDisplayedScrollingRowIndex = i
dgv1.Focus()
'Waits for gFlag to be True
Do
If gFlag = True Then
Exit Do
End If
Loop
'Resets gflag to previous state ie; False in case this function
'is accessed recursively
gFlag = False
'Finds the index of selected Row
i = dgv1.CurrentRow.Index
'Displays the message just to make sure user has chosen a right row just-in-case
C2 = MsgBox("Are you sure that """ & Name & """ is same as """ & dgv1.Rows(i).Cells(1).Value _
& "", MsgBoxStyle.OkCancel)
Select Case C2
'If user confirms then return flag to be true and hence _
'add the value in the selected row of datagridview
Case MsgBoxResult.Ok
flag = True
'If selected row is not same as the desired row then go through a recursive
'Loop
Case MsgBoxResult.Cancel
flag = MakeChoice(Name, i)
End Select
'If C1 = Cancel then add set flag to False ie add the value to a new row
Case MsgBoxResult.Cancel
flag = False
End Select
Return flag
End Function
Function GridClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgv1.Click
'I think this part is self explanatory
gFlag = False
If sender.ToString = "System.Windows.Forms.DataGridView" Then
gFlag = True
End If
Return gFlag
End Function
Hope it helps someone though on hindsight it was not such a big issue I guess. Would be looking for any suggestions to make it better.
Thanks
Jhon