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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Specific Listbox Item Location

Status
Not open for further replies.

lucyv

Programmer
Mar 11, 2002
152
US
On a form I have two listbox controls, each having a few list items. I would like my users to be able to drag an item from one listbox over the another listbox. When the user drops the item I want to draw a line between the item the dragged to the item where they dropped it.

Can anyone tell me how I can programmatically find the exact location of the item that is dropped? I've tried Cursor.Position.X and even the System.Windows.Forms.DragEventArgs argument, but they do not seem to work.

I'd appreciate any kind of help.

-lucyv
 
I've not tested anything, but you might want to have a look at the MouseDown and MouseUp events. These should give you the XY position of the mouse which you could then relate to the positions of the list boxes.

Alternatively, you know the position on the form of the list boxes, you know the height of each item in the list boxes and you know the item number of the source and target items in their respective list boxes. From this you should be able to calculate where to draw the line.

Hope this helps.
 
earthandfire,

I've tried the XY position from the mouse, but this doesn't seem to work. I'm going to try your second suggestion and I'll let you know things to out.

On a side note, when I compare the XY positions of the MouseUp or MouseDown events, it does not match up to the Cursor.Position values.

For example,
Code:
  e.X = 179 and e.Y = 11
whereas
Code:
  Cursor.Position.X = 606 and Cursor.Position.Y = 331
Does anyone know why this is as well?
 
A control's XY in its mouse events refers to the positions WITHIN the control ie 0,0 is top left of the control. The cursor's XY is based on the cursor's postion on the Form.

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top