geht noch weiter:
Protected Overloads Overrides Sub Edit(ByVal source As _
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds _
As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText _
As String, ByVal cellIsVisible As Boolean)
Dim Value As Object
Dim VarText As String
MyBase.TextBox.Visible = False
'Spaltenwert auslesen
Value = CType(GetColumnValueAtRow([source], rowNum), Object)
' Spaltenwert in String umwandeln
If Value.Equals(DBNull.Value) Or Value.Equals(Nothing) Then
VarText = ""
Else
VarText = CStr(Value)
End If
If mEdit = False Then
If CType(source.Current, DataRowView).IsNew Then
' Verhindert in mCheckStateChanged rekursives Auslösen von Edit
mSetText = True
End If
mTextBox.Text = VarText
mSetText = False
End If
If cellIsVisible Then
mTextBox.Bounds = bounds
mTextBox.Visible = True
mTextBox.Focus()
mTextBox.SelectionStart = mTextBox.Text.Length + 1
Else
mTextBox.Visible = False
End If
End Sub
Protected Overrides Function Commit(ByVal dataSource As _
System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer) As Boolean
Dim Value As Object
mTextBox.Visible = False
If mEdit Then
mEdit = False
Select Case mTextBox.Text
Case ""
Value = DBNull.Value
Case Else
Value = mTextBox.Text
End Select
SetColumnValueAtRow(dataSource, rowNum, Value)
End If
Return True
End Function
Protected Overrides Sub Abort(ByVal rowNum As Integer)
MyBase.Abort(rowNum)
mEdit = False
End Sub
Protected Overrides Function GetMinimumHeight() As Integer
If mTextBox.Height >= cMinHeight Then
Return mTextBox.Height
Else
Return cMinHeight
End If
End Function
Protected Overrides Function GetPreferredHeight(ByVal g As _
System.Drawing.Graphics, ByVal value As Object) As Integer
Return mTextBox.Height
End Function
Protected Overrides Function GetPreferredSize(ByVal g As _
System.Drawing.Graphics, ByVal value As Object) As System.Drawing.Size
Return mTextBox.Size
End Function
'Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics,
' ByVal bounds As System.Drawing.Rectangle, ByVal source As
' System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer)
' 'Wird nicht verwendet
'End Sub
'Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing.Graphics,
' ByVal bounds As System.Drawing.Rectangle, ByVal source As
' System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal
' alignToRight As Boolean)
' 'Wird nicht verwendet
'End Sub
Protected Overrides Sub SetDataGridInColumn(ByVal value As DataGrid)
MyBase.SetDataGridInColumn(value)
mDGrid = value
Me.ConcedeFocus()
If Not (mTextBox.Parent Is Nothing) Then
mTextBox.Parent.Controls.Remove(mTextBox)
End If
If Not (value Is Nothing) Then
value.Controls.Add(mTextBox)
End If
End Sub
Private Sub InitTextBox()
mTextBox = New MyTextBox
mTextBox.Visible = False
mTextBox.Multiline = mMultiLine
mTextBox.AcceptsReturn = True
mTextBox.AcceptsTab = False
mTextBox.AutoSize = False
AddHandler mTextBox.BeforeLeaving, AddressOf mTextBox_BeforeLeaving
AddHandler mTextBox.TextChanged, AddressOf mTextBox_TextChanged
End Sub
Private Sub mTextBox_BeforeLeaving(ByRef Value As String, ByRef Cancel As _
Boolean)
mDGrid = Me.DataGridTableStyle.DataGrid
RaiseEvent BeforeColumnUpdate(mDGrid.CurrentCell.RowNumber, _
mDGrid.CurrentCell.ColumnNumber, Value, Cancel)
End Sub
Private Sub mTextBox_TextChanged(ByVal sender As Object, ByVal e As EventArgs)
' mSetText wird in Sub Edit gesetzt, wenn TextChanged durch
' den Wechsel in eine Spalte im DataGrid ausgelöst worden ist.
If Not mSetText Then
If Not mEdit Then
mEdit = True
ColumnStartedEditing(mTextBox)
End If
RaiseEvent TextChanged(mTextBox, mTextBox.Text)
End If
End Sub
Protected Overrides Sub ConcedeFocus()
MyBase.ConcedeFocus()
mTextBox.Visible = False
End Sub
End Class |