Hi I am very new to programming. Managed to make a helpful program last month and am now onto slightly bigger things- DataGridviews are hurting my head. My Datagridview is not bound to a Database. In short i have two DataGridviews on two different forms- one is essentially a Dictionary- and the other is a Data Entry Sheet (a bit like excel). The DataEntry Datagrid Cross references the Dictionary Datagrid. I have got this working however what i need to do is - if the data cell in the data entry sheet is not in the dictionary after editing then it will not go to another cell (IE. stuck in that cell until a correct dictionary value is added. I can currently make it say msgbox"not in dictionary" however my code for not allowing moving out of the cell is not working-
Here is the code
Private Sub dataGridView1_CellEndEdit(ByVal sender As Object,
ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
Handles DataGridView1.CellEndEdit
Dim Row As Integer = DataGridView1.CurrentRow.Index
Dim temp As Integer = 0
Try
For i As Integer = 0 To FormGeoDicLith.DataGridViewDicLith.RowCount - 1
'this code references a column in the datagrid dictionary to see if the correct value has been added to the data entry datagrid
If DataGridView1.Rows(Row).Cells(2).Value = FormGeoDicLith.DataGridViewDicLith.Rows(i).Cells(1).Value Then
MsgBox("Item found")
temp = 1
End If
Next
If temp = 0 Then
'this is the problem area
DataGridView1.Rows(Row).Cells(2).Selected = True
MsgBox("Code Not In Dictionary")
Exit Sub
End If
Catch ex As Exception
End Try
End Sub
The problem is DataGridView1.Rows(Row).Cells(2).Selected = True although it looks like it selects the cell- then it just un-selects and I am not stuck in the cell like i want to be until a correct dictionary item is entered. Help would be very much appreciated.