Results 1 to 3 of 3

Thread: Cancel users attempt to exit cell in a Datagrid

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    69

    Question 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:
    1. Private Sub DataView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellLeave
    2.         If loading = True Then
    3.             Exit Sub
    4.         End If
    5.         Dim colName As String = DataGridView1.Columns(DataGridView1.CurrentCell.ColumnIndex).Name
    6.         Dim rowNo As String = DataGridView1.CurrentCell.RowIndex
    7.         Dim value1 As String = DataGridView1.CurrentCell.EditedFormattedValue
    8.         Dim goodTogo As SQLiteDataReader
    9.  
    10.         Select Case colName
    11.             Case "Timetype"
    12.                 SQLstr = "SELECT name FROM tbltimetype WHERE Name Like '" & value1 & "';"
    13.                 goodToGo= OpenDB(SQLstr, path, mdb).ExecuteReader
    14.                 If goodToGo.Read Then
    15.                      'the value exits in the database, do nothing
    16.                       Exit Sub
    17.                 Else
    18.                       DataGridView1.CancelEdit()
    19.                       'So far so good.. Now how do I maintain focus on this cell??(Not exit it)
    20.  
    21.                 End If
    22.                 goodToGo.Close()
    23.                 closeDB()
    24.             Case 2
    25.  
    26.         End Select
    27.  
    28.     End Sub

    Thanx in advance
    Last edited by Riks; Mar 31st, 2006 at 06:45 AM.

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