Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BUG in ListBox-DoDragDrop-SelectedIndexChanged

194 views
Skip to first unread message

Javed

unread,
Aug 29, 2002, 11:05:24 PM8/29/02
to
There is a bug in the behavior of ListBox. The DoDragDrop
call masks SelectedIndexChanged event.

Steps:
1. Place a Lisbox on a Form. Load it with list of some
kind from a database, perhaps.
2. Place a TextBox on the Form
3. Create a handler for ListBox.SelectedIndexChanged. In
the handler, set the TextBox.Text to the selected item in
the Listbox.
4. Run the program. Click different items in the
ListBox. You should see the text in the TextBox change -
as expected.

NOW

Add another method, this one a Handler for
ListBox.MouseDown as suggested in the Drag-Drop write up
in the MSDN documentation. Here you get the X, Y of
mouse-click, convert the numbers to an index of the item
clicked, and then call ListBox.DoDragDrop()

It is not necessary to create a receptacle for the drop.
The call to ListBox.DoDragDrop we created above
effectively blocks the ListBox.SelectedIndexChanged event.

Run the program again. Click on the ListBox items, there
will be no change in the listbox. In fact the
SelectedIndexChanged event is not even raised.

It is not the MouseDown handler but the call to
DoDragDrop that is the culprit, because if you comment
that one line while leaving the rest of the MouseDown
handler routine intact, the normal behavior returns.

I tried to find a workaround by raising my own DragDrop
event in the ListBox.OnMouseDown, thinking that perhaps
calling MyBase.OnMouseDown before raising the DragDrop
event might help - but it didn't.

Javed

ClayB [Syncfusion]

unread,
Aug 30, 2002, 9:56:58 AM8/30/02
to
The code in this FAQ has checks in the MouseDown handler that prevents the
DoDragDrop from being called unless you mousedown on a selected item and
then try to drag it. Mousingdown on an unselected item does not initiate a
DoDragDrop and this prevents this problem.

George Shepherd's Windows Forms FAQ contains an entry entitled:

How do I implement Drag and Drop support between ListBoxes?

Check it out at:
http://www.syncfusion.com/faq/winforms/search/610.asp

=================================================
Clay Burch, Syncfusion, Inc.

Download a Free Trial of Essential Suite
visit http://www.syncfusion.com for .NET Essentials


"Javed" <ja...@tessdata.com> wrote in message
news:a66701c24fd2$159555b0$3bef2ecf@TKMSFTNGXA10...

0 new messages