![]() |
Tipp 0506
|
Daten mit Drag & Drop in MSHFlexGrid einfügen
|
 |
|
Autor/Einsender: Datum: |
|
Daniel Klatt 01.08.2006 |
|
Entwicklungsumgebung: |
|
VB 6 |
|
|
Der Tipp veranschaulicht, wie mittels Drag & Drop Einträge beispielsweise aus einer ListBox oder Textfeld in ein FlexGrid übertragen werden können.
Da bei einem Drag & Drop-Vorgang immer zuerst das Ereignis OLEStartDrag eines Steuerelements eintritt, wird hier eine globale Variable
mit dem entsprechenden Wert befüllt.
|
Ein Problem bei der Übergabe der Daten liegt darin, dass beim Ablegen eines Items zwar die X/Y-Koordinate des Grids übergeben wird, nicht aber
die Zelle in die das Element abgelegt wurde, daher muss dies gesondert ermittelt werden.
|
Wichtig ist, dass bevor ein Element mit Drag & Drop benutzt werden kann, es immer erst markiert sein muss.
|
|
|
Option Explicit
Dim DDBuffer As String
Private Sub Form_Load()
Dim lngN As Long
Dim Breite As Single
On Error Resume Next
For lngN = 1 To 9
List1.AddItem "Liste " & lngN
Combo1.AddItem "Combo " & lngN
Next
List1.OLEDragMode = 1
grdDaten.OLEDropMode = 1
grdDaten.Rows = 11
grdDaten.Cols = 5
Breite = (grdDaten.Width - 76) / 5
For lngN = 0 To 5
grdDaten.ColWidth(lngN) = Breite
Next lngN
End Sub
Private Sub grdDaten_OLEDragDrop(Data As _
MSHierarchicalFlexGridLib.DataObject, _
Effect As Long, Button As Integer, _
Shift As Integer, x As Single, y As Single)
Dim XPos As Long, YPos As Long
Dim temp() As String
Dim Col As Long, Row As Long
Dim Height As Long, Width As Long
Dim lngN As Long
On Error Resume Next
temp = Split(x, ",")
XPos = CLng(temp(0))
temp = Split(y, ",")
YPos = CLng(temp(0))
For lngN = grdDaten.TopRow To grdDaten.Rows
Height = Height + grdDaten.RowHeight(lngN - 1)
If YPos <= Height Then
Row = lngN - grdDaten.FixedRows
Exit For
End If
Next
For lngN = grdDaten.LeftCol To grdDaten.Cols - 1
Width = Width + grdDaten.ColWidth(lngN)
If XPos <= Width Then
Col = lngN - grdDaten.FixedCols
Exit For
End If
Next
If YPos > Height Then
txtReihe.Text = "undef"
Else
txtReihe.Text = Row
End If
If XPos > Width Then
txtSpalte.Text = "undef"
Else
txtSpalte.Text = Col
End If
If Not (YPos > Height) Then
If Not (XPos > Width) Then
grdDaten.TextMatrix(Row, Col) = DDBuffer
DDBuffer = vbNullString
End If
End If
End Sub
Private Sub Combo1_OLEStartDrag(Data As DataObject, _
AllowedEffects As Long)
DDBuffer = Combo1.Text
End Sub
Private Sub List1_OLEStartDrag(Data As DataObject, _
AllowedEffects As Long)
DDBuffer = List1.Text
End Sub
Private Sub Text1_OLEStartDrag(Data As DataObject, _
AllowedEffects As Long)
DDBuffer = Text1.Text
End Sub
|
|
|
|
|
Windows-Version |
95 |
 |
|
98 |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
VB-Version |
VBA 5 |
 |
|
VBA 6 |
 |
|
VB 4/16 |
 |
|
VB 4/32 |
 |
|
VB 5 |
 |
|
VB 6 |
 |
|
|
|
Download (3,5 kB)
|
Downloads bisher: [ 666 ]
|
|
|