Fragensteller
DatagridView RTFColumn funktioniert noch nicht ganz

Allgemeine Diskussion
-
Halo zusammen,
ich habe versucht aus dem Beispiel für eine CalenderColumn, siehe hier:
https://msdn.microsoft.com/en-us/library/7tas5c80.aspx?f=255&MSPPError=-2147217396
eine Klasse für eine RTFColumn für das DatagridView zu erstellen. Beim Test zeigt sich, dass in eine Zelle RTF-Text eingegeben werden kann über das EditingControl, da sieht man deutlich den formatierten Text. Verlässt man dann allerdings diese Zelle, wird nicht mehr der formatierte Text angezeigt, sondern der RTF-Code.
Ich poste mal den Klassen-Code und vielleicht kann mir jemand sozusagen auf die Sprünge helfen, dass der RTF-Text auch in der Zelle angezeigt wird, denn das ist ja das eigentliche Ziel.
Hier der Code:
Public Class RTFColumn Inherits DataGridViewColumn Public Sub New() MyBase.New(New RTFCell()) End Sub 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 RTFCell. If (value IsNot Nothing) AndAlso Not value.GetType().IsAssignableFrom(GetType(RTFCell)) Then Throw New InvalidCastException("Must be a RTFCell.") End If MyBase.CellTemplate = value End Set End Property End Class Public Class RTFCell Inherits DataGridViewTextBoxCell Public Sub New() End Sub Public Overrides Sub InitializeEditingControl(ByVal rowIndex As Integer, ByVal initialFormattedValue As Object, ByVal dataGridViewCellStyle As DataGridViewCellStyle) ' Set the value of the editing control to the current cell value. MyBase.InitializeEditingControl(rowIndex, initialFormattedValue, dataGridViewCellStyle) Dim ctl As RTFEditingControl = CType(DataGridView.EditingControl, RTFEditingControl) ' Use the default row value when Value property is null. If (Me.Value Is Nothing) Then ctl.Rtf = CType(Me.DefaultNewRowValue, String) Else ctl.Rtf = CType(Me.Value, String) End If End Sub Public Overrides ReadOnly Property EditType() As Type Get ' Return the type of the editing control that RTFCell uses. Return GetType(RTFEditingControl) End Get End Property Public Overrides ReadOnly Property ValueType() As Type Get ' Return the type of the value that RTFCell contains. Return GetType(String) End Get End Property Public Overrides ReadOnly Property DefaultNewRowValue() As Object Get Return "" End Get End Property End Class Class RTFEditingControl Inherits RichTextBox Implements IDataGridViewEditingControl Private dataGridViewControl As DataGridView Private valueIsChanged As Boolean = False Private rowIndexNum As Integer Public Sub New() End Sub Public Property EditingControlFormattedValue() As Object _ Implements IDataGridViewEditingControl.EditingControlFormattedValue Get Return Me.Rtf End Get Set(ByVal value As Object) Try ' This will throw an exception of the string is ' null, empty, or not in the format of a date. Me.Rtf = Rtf Catch ' In the case of an exception, just use the default ' value so we're not left with a null value. Me.Rtf = "" End Try End Set End Property Public Function GetEditingControlFormattedValue(ByVal context _ As DataGridViewDataErrorContexts) As Object _ Implements IDataGridViewEditingControl.GetEditingControlFormattedValue Return Me.Rtf End Function Public Sub ApplyCellStyleToEditingControl(ByVal dataGridViewCellStyle As _ DataGridViewCellStyle) _ Implements IDataGridViewEditingControl.ApplyCellStyleToEditingControl 'Me.Font = dataGridViewCellStyle.Font 'Me.ForeColor = dataGridViewCellStyle.ForeColor 'Me.Backgroundcolor = dataGridViewCellStyle.BackColor End Sub Public Property EditingControlRowIndex() As Integer _ Implements IDataGridViewEditingControl.EditingControlRowIndex Get Return rowIndexNum End Get Set(ByVal value As Integer) rowIndexNum = value End Set End Property Public Function EditingControlWantsInputKey(ByVal key As Keys, ByVal dataGridViewWantsInputKey As Boolean) As Boolean _ Implements IDataGridViewEditingControl.EditingControlWantsInputKey ' Let the cell handle the keys listed. Select Case key And Keys.KeyCode Case Keys.Left, Keys.Up, Keys.Down, Keys.Right, Keys.Home, Keys.End, Keys.PageDown, Keys.PageUp Return True Case Else Return Not dataGridViewWantsInputKey End Select End Function Public Sub PrepareEditingControlForEdit(ByVal selectAll As Boolean) _ Implements IDataGridViewEditingControl.PrepareEditingControlForEdit ' No preparation needs to be done. End Sub Public ReadOnly Property RepositionEditingControlOnValueChange() _ As Boolean Implements _ IDataGridViewEditingControl.RepositionEditingControlOnValueChange Get Return False End Get End Property Public Property EditingControlDataGridView() As DataGridView _ Implements IDataGridViewEditingControl.EditingControlDataGridView Get Return dataGridViewControl End Get Set(ByVal value As DataGridView) dataGridViewControl = value End Set End Property Public Property EditingControlValueChanged() As Boolean _ Implements IDataGridViewEditingControl.EditingControlValueChanged Get Return valueIsChanged End Get Set(ByVal value As Boolean) valueIsChanged = value End Set End Property Public ReadOnly Property EditingControlCursor() As Cursor _ Implements IDataGridViewEditingControl.EditingPanelCursor Get Return MyBase.Cursor End Get End Property Protected Overrides Sub OntextChanged(ByVal eventargs As EventArgs) ' Notify the DataGridView that the contents of the cell have changed. valueIsChanged = True Me.EditingControlDataGridView.NotifyCurrentCellDirty(True) MyBase.OnTextChanged(eventargs) End Sub End Class
Danke im Voraus für Ideen...
Grüße-
Dietrich
- Typ geändert Ivan DragovMicrosoft contingent staff, Moderator Freitag, 28. April 2017 11:14 Keine Antwort