I have multiple listviews on a form (WinForms). List items can be dragged to other listviews. Is there a way to cancel a single item within the dragged items list? The target listview determines whether or not a single item can be dropped there. I'd prefer a solution that will accept all items that are allowed, and reject those that are not. Insights appreciated.

Recommended Answers

All 6 Replies

Perhaps you could manipulate the Tag property of the ListViewItem. Don't no if this will work, never tried it myself, but if I would, I would try this as my first option.

The problem is not identifying which item to allow, but how to cancel it's drag/drop event.

Is it not possible in, the drag/drop events, to check if some flag is set in the Tag object and act accordingly?

The question is HOW to act accordingly.

The easiest way is to set up a proxy list.

In your drag drop event, move the items that you've "dragged" into a secondary list and cancel the entire dragdrop event.

Watch this list for changes. When you detected changes to this list, pull out any you wish to "cancel". Anything you want to keep add to the new ListView and remove from the old ListView manually. You should be able to find them using Equals as they should be object references though I can't confirm this.

This is just an idea, unfortunately dragdrop doesn't do what you want to do natively and this is the best "workaround" I can think of in 2 minutes.

dragdrop doesn't do what you want to do natively

Indeed. I'll give it a try.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.