Я прочитал пост, который вы говорите.Преобразование формы кода c # я получил
Public Class CustomDataGridViewTextBoxEditingControl
Inherits DataGridViewTextBoxEditingControl
Public Overrides Function EditingControlWantsInputKey(ByVal keyData As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean
Select Case keyData And Keys.KeyCode
Case Keys.Enter
Return True
Case Else
End Select
Return MyBase.EditingControlWantsInputKey(keyData, dataGridViewWantsInputKey)
End Function
Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
Select Case e.KeyCode And Keys.KeyCode
Case Keys.Enter
Dim oldSelectionStart As Integer = Me.SelectionStart
Dim currentText As String = Me.Text
Me.Text = String.Format("{0}{1}{2}", currentText.Substring(0, Me.SelectionStart), Environment.NewLine, currentText.Substring(Me.SelectionStart + Me.SelectionLength))
Me.SelectionStart = oldSelectionStart + Environment.NewLine.Length
Case Else
End Select
MyBase.OnKeyDown(e)
End Sub
End Class
Public Class CustomDataGridViewTextBoxCell
Inherits DataGridViewTextBoxCell
Public Overrides ReadOnly Property EditType As Type
Get
Return GetType(CustomDataGridViewTextBoxEditingControl)
End Get
End Property
End Class
Затем в форме, содержащей datagridview (тестовый проект!), Я добавил
Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles
MyBase.Load
Dim col As DataGridViewColumn = Me.DataGridView2.Columns(2)
col.CellTemplate = New CustomDataGridViewTextBoxCell
End Sub
, но не работает.Что не так?