|
-
Mar 31st, 2006, 05:02 AM
#1
Thread Starter
Lively Member
Cancel users attempt to exit cell in a Datagrid
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
Last edited by Riks; Mar 31st, 2006 at 06:45 AM.
-
Mar 31st, 2006, 06:50 AM
#2
Re: Cancel users attempt to exit cell in a Datagrid
You should put a CoMboBox in that column and have the user select a value from a list. That way you're guaranteed of the value entered being valid. Follow the WinForms FAQ link in my signature. That page has lots of good information on various controls, and the DataGrid inparticular. It will have information on putting a ComboBox in a DataGrid.
-
Mar 31st, 2006, 06:56 AM
#3
Thread Starter
Lively Member
Re: Cancel users attempt to exit cell in a Datagrid
Thanx for the reply. I was hoping i wouldnt have to do that, but ill check it
out. Thanx
Riks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|