Hi,
hopefully someone can help me with this little problem.
I have a datagrid where users can edit the values in all cells. I also have a
database containing valid values for all cells in a row. E.g: in the column "Name" the only valid values are "Mort", "Cocher" and "Dew".
So what i need to do is prevent the user from exiting a cell if the value he
has typed doesnt match values in the database.
Can it be done?
what i have so far is this:
VB Code:
Private Sub DataView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave If loading = True Then Exit Sub End If Dim colName As String = DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).Name Dim rowNo As String = DataGridView1.CurrentCell.RowIndex Dim value1 As String = DataGridView1.CurrentCell.EditedFormattedValue Dim goodTogo As SQLiteDataReader Select Case colName Case "Timetype" SQLstr = "SELECT name FROM tbltimetype WHERE Name Like '" & value1 & "';" goodToGo= OpenDB(SQLstr, path, mdb).ExecuteReader If goodToGo.Read Then 'the value exits in the database, do nothing Exit Sub Else DataGridView1.CancelEdit() 'So far so good.. Now how do I maintain focus on this cell??(Not exit it) End If goodToGo.Close() closeDB() Case 2 End Select End Sub
Thanx in advance![]()




Reply With Quote