Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OLE between controls

Status
Not open for further replies.

NFI

Programmer
Jun 7, 2000
278
GB
What-ho,<br><br>&nbsp;&nbsp;does anyone know how to use OLE between controls on a form?&nbsp;&nbsp;More specifically, I'm trying to use the OLEStartDrag event of a tree view control to copy data from that control to a text box control.&nbsp;&nbsp;All the code for this is in the OLEStartDrag event:<br><br>Private Sub treeLinks_OLEStartDrag(Data As MSComctlLib.DataObject, AllowedEffects As Long)<br>&nbsp;&nbsp;&nbsp;&nbsp;AllowedEffects = vbDropEffectCopy<br>&nbsp;&nbsp;&nbsp;&nbsp;Data.Clear<br>&nbsp;&nbsp;&nbsp;&nbsp;Data.SetData treeLinks.SelectedItem.Text, vbCFText<br>End Sub<br><br>&nbsp;&nbsp;However, what seems to be happening is that the node I'm trying to select from the tree view control only becomes the SelectedItem on the mouse up event, so it's not yet selected when the OLEStartDrag event is fired, as, by essence, I'm dragging and I've not yet released the mouse button.&nbsp;&nbsp;The result of this is, the node I drag from isn't the node that's selected and when I release the mouse and finish the OLE drag, it drops the wrong data (it drops data relevant to whichever node is actually the SelectedItem in the treeview control).&nbsp;&nbsp;I was wondering if there's some way of changing the SelectedItem in the treeview control on the treeview Mouse_Down event, but I can't figure out how to detect which node I'm over when the Mouse_Down event is fired.&nbsp;&nbsp;If there's a better (correct) way of using OLE like this, can anyone please help?<br><br>&nbsp;&nbsp;Thanks,<br><br>&nbsp;Paul
 
Hello again,<br><br>&nbsp;&nbsp;typical, innit?&nbsp;&nbsp;You give up on a problem that's been driving you mad for days, start asking everyone for help, get a sudden flash of inspiration and five minutes later you've figured it out.&nbsp;&nbsp;In case anyone else is just dying to know how to solve this problem, here's how:<br><br>&nbsp;The problem is that a node only becomes the SelectedItem on the mouse_up event and OLE takes its data on the mouse_down event.<br><br>&nbsp;&nbsp;First, set a pair of module level variables to keep track of the mouse pointer X Y coordinates within the TreeView control, set them from the TreeView_MouseMove event.<br><br>&nbsp;&nbsp;Now, in the OLEStartDrag event, put this line (or something like it):<br><br>Treeview.SelectedItem = TreeView.HitTest(X, Y)<br><br>&nbsp;&nbsp;where X and Y are your global variables.&nbsp;&nbsp;The HitTest method returns a node object based on the X Y coordinates given it, so this will force the SelectedItem to be the one you've just started your OLE drag from.<br><br>&nbsp;&nbsp;&nbsp;It's all so simple when you know what you're doing...so it's complicated as Hell all the time for me :)<br><br><br>&nbsp;&nbsp;&nbsp;Chars then,<br><br>&nbsp;Paul<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top