Hallo zusammen,
folgende Problematik beschäftigt mich:
Ich habe mehrere CustomCells in einer DataGridView und ziehe diese per DragDrop in eine andere DataGridView. Prinzipiell funktioniert das, allerdings spricht der DragDrop Vorgang nur in einem kleinen Bereich der Zelle an. Im Bild ist dieser Bereicht markiert. In allen anderen Bereichen der Zelle funktioniert das DragDrop nicht.
Meine CustomCell basiert auf einer DataGridViewImageCell:
Spoiler anzeigen
Und noch eine andere Sache zum Thema DragDrop: Zieht man beispielsweise bei Firefox ein Bild mit der Maus, folgt das Bild der Maus. Gibt es hierzu einen Lösungsansatz für die DataGridViewColumn?
Vielen Dank für jegliche Anregungen,
Hajo
folgende Problematik beschäftigt mich:
Ich habe mehrere CustomCells in einer DataGridView und ziehe diese per DragDrop in eine andere DataGridView. Prinzipiell funktioniert das, allerdings spricht der DragDrop Vorgang nur in einem kleinen Bereich der Zelle an. Im Bild ist dieser Bereicht markiert. In allen anderen Bereichen der Zelle funktioniert das DragDrop nicht.
Meine CustomCell basiert auf einer DataGridViewImageCell:
VB.NET-Quellcode
- Imports System.Drawing
- Imports System.ComponentModel
- Public Class DataGridViewDriveColumn
- Inherits DataGridViewImageColumn
- Public Sub New()
- Me.CellTemplate = New DataGridViewDriveCell
- End Sub
- End Class
- Public Class DataGridViewDriveCell
- Inherits DataGridViewImageCell
- Private myFolderSize As Long
- Public Property FolderSize() As Long
- Get
- Return myFolderSize
- End Get
- Set(ByVal Value As Long)
- myFolderSize = Value
- End Set
- End Property
- Private myDriveObject As DriveObject
- Public Property DriveObject() As DriveObject
- Get
- Return myDriveObject
- End Get
- Set(ByVal Value As DriveObject)
- myDriveObject = Value
- End Set
- End Property
- ''' <summary>
- ''' Neuinstanzierung
- ''' </summary>
- ''' <remarks></remarks>
- Sub New()
- ValueType = Type.GetType("String")
- myFolderSize = 0
- myDriveObject = New DriveObject
- End Sub
- ''' <summary>
- ''' Method required to make the Cell consistent with the default Image Cell.
- ''' The default Image Cell assumes an Image as a value, although the value of the Progress Cell is an Integer.
- ''' </summary>
- ''' <param name="value"></param>
- ''' <param name="rowIndex"></param>
- ''' <param name="cellStyle"></param>
- ''' <param name="valueTypeConverter"></param>
- ''' <param name="formattedValueTypeConverter"></param>
- ''' <param name="context"></param>
- ''' <returns></returns>
- ''' <remarks></remarks>
- Protected Overrides Function GetFormattedValue( _
- ByVal value As Object, _
- ByVal rowIndex As Integer, _
- ByRef cellStyle As DataGridViewCellStyle, _
- ByVal valueTypeConverter As TypeConverter, _
- ByVal formattedValueTypeConverter As TypeConverter, _
- ByVal context As DataGridViewDataErrorContexts _
- ) As Object
- Static emptyImage As Bitmap = New Bitmap(1, 1, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
- GetFormattedValue = emptyImage
- End Function
- ''' <summary>
- ''' Zeichnet das Control
- ''' </summary>
- ''' <param name="g"></param>
- ''' <param name="clipBounds"></param>
- ''' <param name="cellBounds"></param>
- ''' <param name="rowIndex"></param>
- ''' <param name="cellState"></param>
- ''' <param name="value"></param>
- ''' <param name="formattedValue"></param>
- ''' <param name="errorText"></param>
- ''' <param name="cellStyle"></param>
- ''' <param name="advancedBorderStyle"></param>
- ''' <param name="paintParts"></param>
- ''' <remarks></remarks>
- Protected Overrides Sub Paint(ByVal g As System.Drawing.Graphics, _
- ByVal clipBounds As System.Drawing.Rectangle, _
- ByVal cellBounds As System.Drawing.Rectangle, _
- ByVal rowIndex As Integer, _
- ByVal cellState As System.Windows.Forms.DataGridViewElementStates, _
- ByVal value As Object, _
- ByVal formattedValue As Object, _
- ByVal errorText As String, _
- ByVal cellStyle As System.Windows.Forms.DataGridViewCellStyle, _
- ByVal advancedBorderStyle As System.Windows.Forms.DataGridViewAdvancedBorderStyle, _
- ByVal paintParts As System.Windows.Forms.DataGridViewPaintParts)
- Dim myForeBrush As Brush = New SolidBrush(cellStyle.ForeColor)
- Dim myIconWidth As Integer = 32
- 'Zeichnet die Standardansicht der Zelle
- MyBase.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, _
- advancedBorderStyle, paintParts)
- 'Icon
- g.DrawImage(My.Resources.drive, New Point(cellBounds.X + 18, cellBounds.Y + 6))
- 'Text
- g.DrawString("(" & myDriveObject.DriveName & ") " & myDriveObject.VolumeLabel, cellStyle.Font, myForeBrush, _
- cellBounds.X + 18 + myIconWidth + 6, cellBounds.Y + 15)
- End Sub
- End Class
Und noch eine andere Sache zum Thema DragDrop: Zieht man beispielsweise bei Firefox ein Bild mit der Maus, folgt das Bild der Maus. Gibt es hierzu einen Lösungsansatz für die DataGridViewColumn?
Vielen Dank für jegliche Anregungen,
Hajo