We will customize the behavior of the fgDDManual control as an OLE drop target so that when a list of files is dropped, it opens the first file on the list and displays the contents of the first 10 lines in that file. (The default behavior is to treat lists of files as text, and paste the file names.)
When the user drops an OLE data object on a VSFlexGrid control with the OLEDropMode property set to flexOLEDropManual, the control fires the OLEDragDrop event. The data object being dropped is passed as a parameter (Data) that you may query for the type of data you want.
The routine below checks to see if Data contains a list of files. If so, it opens the first file on the list and reads the contents of its first 10 lines. If the Data parameter does not contain any files, then the routine tries to get its text contents. Either way, the routine transfers the data to the grid using the Clip property.
Here is the routine:
Private Sub fgDDManual_OLEDragDrop(Data As VSFlex8Ctl.vsDataObject, _
Effect As Long, _
ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, ByVal Y As Single)
Dim r As Long, c As Long, i As Integer, s As String
With fgDDManual
' get drop location
r = .MouseRow
c = .MouseCol
' if we're dropping files, open the file
' and paste contents
If Data.FileCount > 0 Then
On Error Resume Next
Open Data.Files(0) For Input As #1
For i = 0 To 10
Line Input #1, s
.Cell(flexcpText, r + i, c) = s
Next
Close #1
' drop text using the Clip property
ElseIf Data.GetFormat(vbCFText) Then
s = Data.GetData(vbCFText)
.Select r, c, .Rows - 1, .Cols - 1
.Clip = s
.Select r, c
' we don't accept anything else
Else
MsgBox "Sorry, we only accept text and files..."
End If
End With
End Sub
That concludes this demo. Run the project again and try dragging and dropping between the controls and other applications.