<System.ComponentModel.DefaultBindingProperty("Text")> _
Public Class myUserControlTest
Public Overrides Property Text() As String
Get
Return Me.ilMioDato.Text
End Get
Set(ByVal value As String)
Me.ilMioDato.Text = value
End Set
End Property
Private Sub ilMioDato_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ilMioDato.TextChanged
Me.ilMioRisultato.Text = Me.ilMioDato.Text.Length
End Sub
End Class
Public Class NDC
Inherits DataGridViewTextBoxCell
Public Overrides ReadOnly Property EditType() As System.Type
Get
Return GetType(myUserControlTest_DGVColumnType)
End Get
End Property
Public Overrides ReadOnly Property ValueType() As System.Type
Get
Return GetType(String)
End Get
End Property
End Class
Public Class myUserControlTest_WithCalendarDGVColumn
Inherits DataGridViewColumn
Public Sub New()
MyBase.new(New NDC)
End Sub
' ---> KKKKK
Public Overrides Property CellTemplate() As DataGridViewCell
Get
Return MyBase.CellTemplate
End Get
Set(ByVal value As DataGridViewCell)
' Ensure that the cell used for the template is a NDC.
If (value IsNot Nothing) AndAlso _
Not value.GetType().IsAssignableFrom(GetType(NDC)) _
Then
Throw New InvalidCastException("Must be a NDC")
End If
MyBase.CellTemplate = value
End Set
End Property
' <--- KKKKK
End Class
Class myUserControlTest_DGVColumnType
'this is the new class to get your usercontrol into the datagridcolumn class
'here your have to change only the first line i.e inherits tbnumber to inherit 'your user control. Remianing all codes are for datagridview to track the keys 'and values. you need not change anything
Inherits myUserControlTest
' (this usercontrol is for getting numeric input only)
' You can get this code for this class in my other thread
' here after you need not change any code
Implements IDataGridViewEditingControl
Private _dataGridView As DataGridView
Private _rowIndex As Integer
Private _valueChanged As Boolean
Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As DataGridViewCellStyle) _
Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl
Me.BackColor = dataGridViewCellStyle.BackColor
Me.Font = dataGridViewCellStyle.Font
Me.ForeColor = dataGridViewCellStyle.ForeColor
End Sub
Public Property EditingControlDataGridView() As DataGridView _
Implements IDataGridViewEditingControl.EditingControlDataGridView
Get
Return _dataGridView
End Get
Set(ByVal value As DataGridView)
_dataGridView = value
End Set
End Property
Public Property EditingControlFormattedValue() As Object _
Implements IDataGridViewEditingControl.EditingControlFormattedValue
Get
Return Text
End Get
Set(ByVal value As Object)
Text = value.ToString()
End Set
End Property
Public Property EditingControlRowIndex() As Integer _
Implements IDataGridViewEditingControl.EditingControlRowIndex
Get
Return _rowIndex
End Get
Set(ByVal value As Integer)
_rowIndex = value
End Set
End Property
Public Property EditingControlValueChanged() As Boolean _
Implements IDataGridViewEditingControl.EditingControlValueChanged
Get
Return _valueChanged
End Get
Set(ByVal value As Boolean)
_valueChanged = value
End Set
End Property
Public Function EditingControlWantsInputKey(ByVal keyData As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean _
Implements IDataGridViewEditingControl.EditingControlWantsInputKey
Return True
End Function
Public ReadOnly Property EditingPanelCursor() As Cursor _
Implements IDataGridViewEditingControl.EditingPanelCursor
Get
Return MyBase.Cursor
End Get
End Property
Public Function GetEditingControlFormattedValue(ByVal context As DataGridViewDataErrorContexts) As Object _
Implements IDataGridViewEditingControl.GetEditingControlFormattedValue
Return Text
End Function
Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _
Implements IDataGridViewEditingControl.PrepareEditingControlForEdit
End Sub
Public ReadOnly Property RepositionEditingControlOnValueChange() As Boolean _
Implements IDataGridViewEditingControl.RepositionEditingControlOnValueChange
Get
Return False
End Get
End Property
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
MyBase.OnTextChanged(e)
_valueChanged = True
_dataGridView.NotifyCurrentCellDirty(True)
End Sub
End Class