摘录.在没有OlE拖动功能的控件上实现OLE拖动.
可以把这个原理应用在Access中.但是前提是要richTextBox.visible=true.在VB环境中无此要求
原文:
Use OLE Drag-and-Drop With a DBGrid
Control
It’s easy to drag-and-drop from a DBGrid to Word or Excel, even
though DBGrids don’t support OLE Automation. Just add a rich
textbox to your form and make it invisible. Also set its OLEDragMode
to 0 - rtfOLEDragManual. Then in the DBGrid’s MouseMove event,
add this code:
Private Sub DBGrid1_MouseMove(Button As _
Integer,
Shift As Integer, X As _
Single, Y As
Single)
' start the
drag from here...
If Button = vbLeftButton
Then
rtfDrag.OLEDrag
End If
End Sub
In the rich textbox’s OLEStartDrag event, set up the allowed format
and effect:
Private Sub rtfDrag_OLEStartDrag(Data As _
RichTextLib.DataObject, AllowedEffects As Long)
' valid formats and effects
Data.SetData , vbCFRTF
Data.SetData , vbCFText
AllowedEffects = vbDropEffectCopy
End Sub
In the OLESetData event for the rich textbox, you must generate
the data you want to export. You can include tabs, or you can
create a table in Word, select it, and drop it on the rich textbox to
see what code it generates.
It’s easy to drag-and-drop from a DBGrid to Word or Excel, even
though DBGrids don’t support OLE Automation. Just add a rich
textbox to your form and make it invisible. Also set its OLEDragMode
to 0 - rtfOLEDragManual. Then in the DBGrid’s MouseMove event,
add this code:
Private Sub DBGrid1_MouseMove(Button As _
End Sub
In the rich textbox’s OLEStartDrag event, set up the allowed format
and effect:
Private Sub rtfDrag_OLEStartDrag(Data As _
End Sub
In the OLESetData event for the rich textbox, you must generate
the data you want to export. You can include tabs, or you can
create a table in Word, select it, and drop it on the rich textbox to
see what code it generates.
浙公网安备 33010602011771号