<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Farooq Azam &#187; drop</title>
	<atom:link href="http://www.farooqazam.net/tag/drop/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.farooqazam.net</link>
	<description>C# &#38; .NET Programming Blog</description>
	<lastBuildDate>Fri, 23 Jul 2010 20:15:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Drag and Drop using C#</title>
		<link>http://www.farooqazam.net/drag-and-drop-using-c-sharp/</link>
		<comments>http://www.farooqazam.net/drag-and-drop-using-c-sharp/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 11:31:14 +0000</pubDate>
		<dc:creator>Farooq Azam</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[c sharp]]></category>
		<category><![CDATA[drag]]></category>
		<category><![CDATA[drop]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.farooqazam.net/?p=39</guid>
		<description><![CDATA[I was working on an App and needed Drag &#38; Drop support for it. I thought it&#8217;ll be complicated but its very easy. Here&#8217;s how its done: For this tutorial I&#8217;ll be using a listBox. You can use any control but make sure you set the &#8220;AllowDrop&#8221; to &#8220;true&#8220;. Checking what has been dragged Select [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px; margin-top: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.farooqazam.net%2Fdrag-and-drop-using-c-sharp%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.farooqazam.net%2Fdrag-and-drop-using-c-sharp%2F&amp;source=farooqaaa&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>I was working on an App and needed Drag &amp; Drop support for it. I thought it&#8217;ll be complicated but its very easy. Here&#8217;s how its done:</p>
<p>For this tutorial I&#8217;ll be using a listBox. You can use any control but make sure you set the <strong>&#8220;AllowDrop&#8221; </strong>to<strong> &#8220;true</strong>&#8220;.</p>
<h3>Checking what has been dragged</h3>
<p>Select the listBox and add the DragEnter event.</p>
<p>Add this code:</p>
<pre class="brush: csharp;">
private void listBox1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)
 {

 // This will make sure that a file has been dropped and not text,folders or something else

 if (e.Data.GetDataPresent(DataFormats.FileDrop, false))

 {

 // This will allow the files to be dragged into the control

 e.Effect = DragDropEffects.All;

 }

 }</pre>
<p>The above code first makes sure that files are dragged and not text, folders etc; and then allows the files to be dragged into the control.</p>
<p><span id="more-39"></span></p>
<h3>Handling the drop</h3>
<p>Select the listBox and add the DragDrop event.</p>
<p>Add this code:</p>
<pre class="brush: csharp;">  private void listBox1_DragDrop(object sender,System.Windows.Forms.DragEventArgs e)

    // Save the filenames of the dragged files into a string[] array

    string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

    foreach (string fileNames in files )

    {

    // Add all the file names to the listBox

    listBox1.Items.Add( fileNames );

    }

    }</pre>
<p>And that&#8217;s it.</p>
<p>If you want to do something different with the drag/drop files instead of only adding it to the listBox, don&#8217;t hesitate to post a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.farooqazam.net/drag-and-drop-using-c-sharp/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
