I add a user control (a simple textbox control) to customize
datagridview column to test how to add user control to datagridview. I
found a weired behavior. I can not input "q", "!", "#".
But I can input other keys (e.g. "Q", "@", "W")
Anybody found this question? It looks like the textbox eat the input
'q' and does not show up in the text.
Public Class DataGridViewEditorButtonEditingControl
Inherits TextBox
Implements IDataGridViewEditingControl
#Region "Vars"
'The grid that owns this editing control
Private dataGridViewControl As DataGridView
'Stores whether the editing control's value has changed or not
Private valueIsChanged As Boolean = False
'Stores the row index in which the editing control resides
Private rowIndexNum As Integer
#End Region
#Region "Implements IDataGridViewEditingControl"
Public Sub ApplyCellStyleToEditingControl(ByVal
dataGridViewCellStyle As System.Windows.Forms.DataGridViewCellStyle)
Implements
System.Windows.Forms.IDataGridViewEditingControl.A pplyCellStyleToEditingControl
End Sub
Public Property EditingControlDataGridView() As
System.Windows.Forms.DataGridView Implements
System.Windows.Forms.IDataGridViewEditingControl.E ditingControlDataGridView
Get
Return dataGridViewControl
End Get
Set(ByVal value As System.Windows.Forms.DataGridView)
dataGridViewControl = value
End Set
End Property
Public Property EditingControlFormattedValue() As Object
Implements
System.Windows.Forms.IDataGridViewEditingControl.E ditingControlFormattedValue
Get
Return Me.Text
End Get
Set(ByVal value As Object)
If TypeOf value Is [String] Then
Me.Text = value
Else
Me.Text = ""
End If
End Set
End Property
Public Property EditingControlRowIndex() As Integer Implements
System.Windows.Forms.IDataGridViewEditingControl.E ditingControlRowIndex
Get
Return rowIndexNum
End Get
Set(ByVal value As Integer)
rowIndexNum = value
End Set
End Property
Public Property EditingControlValueChanged() As Boolean
Implements
System.Windows.Forms.IDataGridViewEditingControl.E ditingControlValueChanged
Get
Return valueIsChanged
End Get
Set(ByVal value As Boolean)
valueIsChanged = value
End Set
End Property
Public Function EditingControlWantsInputKey(ByVal keyData As
System.Windows.Forms.Keys, ByVal dataGridViewWantsInputKey As Boolean)
As Boolean Implements
System.Windows.Forms.IDataGridViewEditingControl.E ditingControlWantsInputKey
Select Case (keyData)
Case Keys.Enter
Return True
Case Else
Return False
End Select
End Function
Public ReadOnly Property EditingPanelCursor() As
System.Windows.Forms.Cursor Implements
System.Windows.Forms.IDataGridViewEditingControl.E ditingPanelCursor
Get
Return MyBase.Cursor
End Get
End Property
Public Function GetEditingControlFormattedValue(ByVal context
As System.Windows.Forms.DataGridViewDataErrorContexts ) As Object
Implements
System.Windows.Forms.IDataGridViewEditingControl.G etEditingControlFormattedValue
Return Me.Text
End Function
Public Sub PrepareEditingControlForEdit(ByVal selectAll As
Boolean) Implements
System.Windows.Forms.IDataGridViewEditingControl.P repareEditingControlForEdit
'Do not select all the text, but position the caret at the
start of the text
Me.SelectionStart = 0
Me.SelectionLength = 0
End Sub
Public ReadOnly Property
RepositionEditingControlOnValueChange() As Boolean Implements
System.Windows.Forms.IDataGridViewEditingControl.R epositionEditingControlOnValueChange
Get
Return False
End Get
End Property
#End Region
End Class