R
Robert Styma
Hi,
I have a datagridview which is not linked to a database. I have added
keypress and keydown handlers for the table elements using the following code:
Private Sub DisplayContestantList_EditingControlShowing(ByVal sender As
Object, ByVal e As
System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles
DisplayReqsList.EditingControlShowing
If Me.HandlerAdded = False And Not e.Control Is Nothing Then
Dim tb As TextBox = CType(e.Control, TextBox)
'---add an event handler to the TextBox control---
RemoveHandler DirectCast(e.Control, TextBox).KeyPress, AddressOf
DisplayReqsList_KeyPressEvent
AddHandler tb.KeyPress, AddressOf DisplayReqsList_KeyPressEvent
RemoveHandler DirectCast(e.Control, TextBox).KeyDown, AddressOf
DisplayReqsList_KeyDown
AddHandler tb.KeyDown, AddressOf DisplayReqsList_KeyDown
Me.HandlerAdded = True
End If
End Sub ' DisplaycontestantList_EditingControlShowing
Private Sub DisplayReqsList_KeyDown(ByVal eventSender As System.Object,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles DisplayReqsList.KeyDown
Dim Row As Integer
Dim Col As Integer
Dim Val As String
Row = Me.DisplayReqsList.CurrentCell.RowIndex
Col = Me.DisplayReqsList.CurrentCell.ColumnIndex
Me.DisplayReqsList.UpdateCellValue(Col, Row)
Val = Me.DisplayReqsList.Item(Col, Row).Value.ToString
If e.KeyCode = Keys.F1 Then
MessageBox.Show(Val)
End If
End Sub ' DisplayContestantList_KeyPressEvent
Private Sub DisplayReqsList_KeyPressEvent(ByVal eventSender As
System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles
DisplayReqsList.KeyPress
Dim Row As Integer
Dim Col As Integer
Dim Val As String
Row = Me.DisplayReqsList.CurrentCell.RowIndex
Col = Me.DisplayReqsList.CurrentCell.ColumnIndex
Val = Me.DisplayReqsList.Item(Col, Row).Value.ToString
MessageBox.Show(Val)
End Sub ' DisplayContestantList_KeyPressEvent
The DataGridView is using the default "EditOnKeystrokeOrF2" setting.
The handlers execute as expected. However, in the handler, I attempt to get
the current data in the cell. It always shows up as blank or whatever it was
when the editing started. Charaters previously typed do not show up in "Val".
If I switch to "EditProgramatically", I can get the current data, but then I
have to
handle backspaces, highlighted areas, delete and such on my own.
What I am doing is allowing the user to type a few characters and then press
a function key. Based on what they typed in the cell, I take different
actions and
will update the cell. Kind of an auto-completion.
I am guessing the current data in the cell being edited is held in a
different control.
If so, is there a way to get to the control?
If there is please let me know.
My current workaround is to make the datagrid read only and pop a dialog box
with a textbox on double click of a cell. I then do the processing in the
text box
and put the data back when the dialog box closes. This is kind of clumsy.
Any suggestions are welcome.
I have a datagridview which is not linked to a database. I have added
keypress and keydown handlers for the table elements using the following code:
Private Sub DisplayContestantList_EditingControlShowing(ByVal sender As
Object, ByVal e As
System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles
DisplayReqsList.EditingControlShowing
If Me.HandlerAdded = False And Not e.Control Is Nothing Then
Dim tb As TextBox = CType(e.Control, TextBox)
'---add an event handler to the TextBox control---
RemoveHandler DirectCast(e.Control, TextBox).KeyPress, AddressOf
DisplayReqsList_KeyPressEvent
AddHandler tb.KeyPress, AddressOf DisplayReqsList_KeyPressEvent
RemoveHandler DirectCast(e.Control, TextBox).KeyDown, AddressOf
DisplayReqsList_KeyDown
AddHandler tb.KeyDown, AddressOf DisplayReqsList_KeyDown
Me.HandlerAdded = True
End If
End Sub ' DisplaycontestantList_EditingControlShowing
Private Sub DisplayReqsList_KeyDown(ByVal eventSender As System.Object,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles DisplayReqsList.KeyDown
Dim Row As Integer
Dim Col As Integer
Dim Val As String
Row = Me.DisplayReqsList.CurrentCell.RowIndex
Col = Me.DisplayReqsList.CurrentCell.ColumnIndex
Me.DisplayReqsList.UpdateCellValue(Col, Row)
Val = Me.DisplayReqsList.Item(Col, Row).Value.ToString
If e.KeyCode = Keys.F1 Then
MessageBox.Show(Val)
End If
End Sub ' DisplayContestantList_KeyPressEvent
Private Sub DisplayReqsList_KeyPressEvent(ByVal eventSender As
System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles
DisplayReqsList.KeyPress
Dim Row As Integer
Dim Col As Integer
Dim Val As String
Row = Me.DisplayReqsList.CurrentCell.RowIndex
Col = Me.DisplayReqsList.CurrentCell.ColumnIndex
Val = Me.DisplayReqsList.Item(Col, Row).Value.ToString
MessageBox.Show(Val)
End Sub ' DisplayContestantList_KeyPressEvent
The DataGridView is using the default "EditOnKeystrokeOrF2" setting.
The handlers execute as expected. However, in the handler, I attempt to get
the current data in the cell. It always shows up as blank or whatever it was
when the editing started. Charaters previously typed do not show up in "Val".
If I switch to "EditProgramatically", I can get the current data, but then I
have to
handle backspaces, highlighted areas, delete and such on my own.
What I am doing is allowing the user to type a few characters and then press
a function key. Based on what they typed in the cell, I take different
actions and
will update the cell. Kind of an auto-completion.
I am guessing the current data in the cell being edited is held in a
different control.
If so, is there a way to get to the control?
If there is please let me know.
My current workaround is to make the datagrid read only and pop a dialog box
with a textbox on double click of a cell. I then do the processing in the
text box
and put the data back when the dialog box closes. This is kind of clumsy.
Any suggestions are welcome.