473,779 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drag and Drop in a ListView

I wrote an C# application that uses drag and drop to copy the contents of
one ListViewItem to another. I call DoDragDrop() in the ItemDrag event
handler, however, the ItemDrag event is being fired when an item in the
ListView is clicked to select it instead of being fired when the item is
dragged.

This is causing a problem when users click on an item and move the moue
(after the mouse button has been released) because the app tries to perform
the drag and drop operation, copy, even though the item wasn't dragged to
another item before the mouse button was released.

I have tried implementing handlers for the MouseUpand QueryContinueDr ag
events to cancel the drag and drop if the mouse button is released over the
selected item. Neither event handler is hit before the mouse is moved off
the selected item.

I need to find a way to cancel the drag or even better to find out how to
prevent ItemDrag from firing when the ListViewitem is clicked on to select
it.

Has anyone got any suggestions about how to solve this problem?

Thanks,
Tom
Mar 24 '08 #1
2 3471
Hi Tom,

Thank you for your prompt reply!

I performed a test on your new finding. I add some lines of code which will
take several seconds to complete in the SelectedIndexCh anged event handler
as follows:

void listView1_Selec tedIndexChanged (object sender, EventArgs e)
{
Console.WriteLi ne("begin: selected index changed");
int j = 0;
for (int i = 0; i < 10000; i++)
{
for (int k = 0; k < 10000; k++)
{
j += i;
}
}
Console.WriteLi ne("end: selected index changed");
}

void listView1_ItemD rag(object sender, ItemDragEventAr gs e)
{
Console.WriteLi ne("item drag");
}

Then I run my test application by pressing F5 and select and drag one item
in the ListView. The result I get is that the string "item drag" is always
printed after the string "end: selected index changed" in the Output
window, which means the ItemDrag event handler is called only after the
SelectedIndexCh anged event handler is completed.

If you don't call the time-consuming method from within the
SelectedIndexCh anged event handler, does the problem disappear? If so, you
may have a try calling the Control.BeginIn voke method to execute a delegate
for the time-consuming method asynchronously.

Hope this helps.
If the problem is still not solved, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Mar 26 '08 #2
Hi Tom,

Thank you for your prompt reply!

Is the problem solved now? If not, please feel free to let me know.

Thank you for using our MSDN Managed Newsgroup Support Service!

Sincerely,
Linda Liu
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsof t.com.

This posting is provided "AS IS" with no warranties, and confers no rights.
Mar 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1459
by: Marco Auday | last post by:
I need to associate items in two listviews. I have got the drag-and-drop operation to perform as I wanted. However, I would like the items in the target listview to be highlighted when the mouse hovers over them during the drag-and-drop operation, so that I know for sure which item I selected on the target listview. I have tried a number of approaches without success, including: 1) TargetListview.DragEnter event – tried to...
1
312
by: Jim McLeod | last post by:
Dear Group How am I going wrong with this drag and drop procedure.. private void ResourceList_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e System.Windows.Forms.ListView ListView = (System.Windows.Forms.ListView)sender System.Collections.ArrayList ListItemArrayList = new ArrayList() foreach(System.Windows.Forms.ListViewItem Item in ListView.SelectedItems
0
1247
by: Lloyd Sheen | last post by:
In my application I have a ListView of files that meet certain criteria. I have implemented drag/drop from this list to a second ListView of selected items. This works well and will accept a filelist from windows explorer. Now I want to be able to drag the selected items in the second ListView (selected by checkbox) to an external application such as Media Player. In my DataObject created to do the drag and drop internally I create an...
3
10599
by: VB Programmer | last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2 listboxes? Thanks!
2
9710
by: TarheelsFan | last post by:
I am having problems with drag and drop into a listview. I am able to drag and drop items from within the listview, as well as drag items from the listview and drop into a picturebox. However, I am not able to drag the text or image from the picturebox to the listview. In the listview_dragenter function, I have e.Effects = DragDropEffects.Copy (I have also tried e.Effects = DragDropEffects.Move, but it does not help either), which is...
1
5375
by: Sim | last post by:
Hello NG, I try to use drag and drop function between two list views. For this I found following code: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchimpdragdrop.asp It works fine, but I have another problem. I want to create functionality like a Windows Explorer. This means, if I select some items from list view No 1 and drag&drop this to the list view No 2, then I want to mark automatically
2
2545
by: ngajjar | last post by:
An application I am working with has two listview controls. Items are added runtime from the database when form load. It requires a mechanism which allow user to drag item from a listview and drop in another listview. In code behind it should update the database.
0
2180
by: jawilson | last post by:
Hello, I am trying to use drag-n-drop for a listview control in my program. I created a new listview control class (just call it MyListView) that inherits from ListView, and creates a few new properties and methods. I have set AllowDrop to true, and have all of the Drag* events written. In addition, the listview is in the detailed view. A simple explanation of what I want to do is to drag a file from the desktop or explorer into my...
2
3749
by: jmDesktop | last post by:
I have two listview controls. I have three items of text. I can drag and drop the listview items between each other, back and forth. But the images from the imagelist do not copy over from listview1 to listview2, only the text does. Both listviews have their smallimagelist as the single imagelist I have. Here is my code and thank you for any help. private void listView1_ItemDrag(object sender, ItemDragEventArgs e) { int max =...
0
9632
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.