<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Lazarus - Drag and Drop items in the same TListBox - Delphi, Lazarus, Free Pascal				            </title>
            <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-drag-and-drop-items-in-the-same-tlistbox/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Tue, 09 Jun 2026 03:19:59 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Lazarus - Drag and Drop items in the same TListBox</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-drag-and-drop-items-in-the-same-tlistbox/#post-790</link>
                        <pubDate>Mon, 14 Sep 2015 08:58:05 +0000</pubDate>
                        <description><![CDATA[Side note, to make just Clicking (selecting) an item possible:Set DragMode:=dmAutomatic for the ListBox or CheckListBox.]]></description>
                        <content:encoded><![CDATA[<p>Side note, to make just Clicking (selecting) an item possible:</p><p>Set <b>DragMode:=dmAutomatic</b> for the ListBox or CheckListBox.</p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-drag-and-drop-items-in-the-same-tlistbox/#post-790</guid>
                    </item>
				                    <item>
                        <title>Lazarus - Drag and Drop items in the same TListBox</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-drag-and-drop-items-in-the-same-tlistbox/#post-273</link>
                        <pubDate>Mon, 14 Sep 2015 07:21:04 +0000</pubDate>
                        <description><![CDATA[This is just an example how you can use Drag and Drop to change the order of items is a TListBox or a TCheckListBox.First we define a global variable, this can be a property of TForm1 for ex...]]></description>
                        <content:encoded><![CDATA[<p>This is just an example how you can use Drag and Drop to change the order of items is a TListBox or a TCheckListBox.</p><p>First we define a global variable, this can be a property of TForm1 for example;</p><pre>&nbsp; DraggingItemNumber : integer;</pre><p>Next we define 3 procedures for the ListBox events "OnMouseDown", "OnDragDrop", "OnDragOver".</p><p>We use OnMouseDown to identify that the user clicked a mouse button (this can be left or right mouse button), where we determine if a proper item has been selected and store that item number in the global variable.</p><p>The OnDragOver event is used to make sure the item has a place to drop, on it's own control. If that's the case we gladly accept a potential drop (mouse cursor changes).</p><p>The onDragDrop even is used to "receive" the dropped item and, if everything is legit, move the dragged item to the new location.</p><pre>procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);<br>begin<br>&nbsp; DraggingItemNumber := ListBox1.ItemAtPos(Point(X,Y), true);<br>&nbsp; if (DraggingItemNumber&gt;-1) and (DraggingItemNumber&lt;ListBox1.Count) then<br>&nbsp; &nbsp; ListBox1.BeginDrag(true)<br>&nbsp; else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ListBox1.BeginDrag(False);<br>&nbsp; &nbsp; &nbsp; DraggingItemNumber:=-1;<br>&nbsp; &nbsp; end;<br>end; &nbsp; &nbsp;
procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);<br>var ItemUnderMouse:integer;<br>begin<br>&nbsp; ItemUnderMouse := ListBox1.ItemAtPos(Point(X,Y), true);<br>&nbsp; if (ItemUnderMouse&gt;-1) and (ItemUnderMouse&lt;ListBox1.Count) and (DraggingItemNumber&gt;-1) then<br>&nbsp; &nbsp; listShares.Items.Move(DraggingItemNumber,ItemUnderMouse);<br>end;
procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean);<br>var ItemUnderMouse:integer;<br>begin<br>&nbsp; if Sender=Source then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ItemUnderMouse := ListBox1.ItemAtPos(Point(X,Y), true);<br>&nbsp; &nbsp; &nbsp; Accept:=(ItemUnderMouse&gt;-1) and (ItemUnderMouse&lt;ListBox1.Count);<br>&nbsp; &nbsp; end<br>&nbsp; else<br>&nbsp; &nbsp; Accept:=false;<br>end; &nbsp; &nbsp;</pre><p><br></p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-drag-and-drop-items-in-the-same-tlistbox/#post-273</guid>
                    </item>
							        </channel>
        </rss>
		