<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Reordering a list box in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Reordering-a-list-box/m-p/737130#M91813</link>
    <description>&lt;P&gt;I would like to be able to reorder a list in a list box, ideally with drag and drop (which seems impossible) or else with buttons. I'm looking for JSL for the up and down buttons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The bigger goal is to get all files in a directory, split them into two lists based on file extensions. Display the two lists to the user, allow them to reorder the files so that pairs match up. Hit Ok to get the filename lists from the 2 list boxes and execute code on them in pairs. I just need help with the reordering of the lists in the list boxes.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Mar 2024 11:40:54 GMT</pubDate>
    <dc:creator>pauldeen</dc:creator>
    <dc:date>2024-03-21T11:40:54Z</dc:date>
    <item>
      <title>Reordering a list box</title>
      <link>https://community.jmp.com/t5/Discussions/Reordering-a-list-box/m-p/737130#M91813</link>
      <description>&lt;P&gt;I would like to be able to reorder a list in a list box, ideally with drag and drop (which seems impossible) or else with buttons. I'm looking for JSL for the up and down buttons.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The bigger goal is to get all files in a directory, split them into two lists based on file extensions. Display the two lists to the user, allow them to reorder the files so that pairs match up. Hit Ok to get the filename lists from the 2 list boxes and execute code on them in pairs. I just need help with the reordering of the lists in the list boxes.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Mar 2024 11:40:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Reordering-a-list-box/m-p/737130#M91813</guid>
      <dc:creator>pauldeen</dc:creator>
      <dc:date>2024-03-21T11:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering a list box</title>
      <link>https://community.jmp.com/t5/Discussions/Reordering-a-list-box/m-p/737152#M91814</link>
      <description>&lt;P&gt;Here is one very quick version for buttons (modified from&amp;nbsp;&lt;LI-MESSAGE title="Column Quick Swapper - easily change multiple Y and X-axis columns in Graph Builder" uid="724616" url="https://community.jmp.com/t5/JMP-Add-Ins/Column-Quick-Swapper-easily-change-multiple-Y-and-X-axis-columns/m-p/724616#U724616" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

move_items = function({lb_ref, direction}, {Default Local},
	all_items = lb_ref &amp;lt;&amp;lt; Get Items;
	sel_items = lb_ref &amp;lt;&amp;lt; Get Selected;
	
	If(direction == "Swap",
		item_order = Transform Each({sel_item}, sel_items,
			Contains(all_items, sel_item)
		);
		new_order = all_items;
		new_order[item_order] = Reverse(sel_items);
	,
		start_idx = Contains(all_items, sel_items[1]); // set based first found item
		new_list = Filter Each({cur_item}, all_items, !Contains(sel_items, cur_item));
		
		new_idx = If(direction == "Up",
			start_idx - 1;
		, direction == "Down",
			start_idx + 1
		,
			start_idx
		);
		new_order = Insert(new_list, sel_items, new_idx);
	);
	
	lb_ref &amp;lt;&amp;lt; Set Items(new_order);
	
	all_items = lb_ref &amp;lt;&amp;lt; Get Items;
	For Each({cur_item}, sel_items,
		new_idx = Contains(all_items, cur_item);
		lb_ref &amp;lt;&amp;lt; Set Selected(new_idx, 1, Run Script(0));
	);
);

nw = New Window("Example",
	H List Box(
		lb_ref = List Box(
			{"First Item", "Second Item", "Third Item"},
			width(200),
			max selected(2),
			nlines(6)
		),
		Lineup Box(N Col(1),
			btn_up = Button Box("", move_items(lb_ref, "Up"), &amp;lt;&amp;lt; Set Icon("ListItemUp"), &amp;lt;&amp;lt; Set Tip("Move selection up")),
			btn_down = Button Box("", move_items(lb_ref, "Down"), &amp;lt;&amp;lt; Set Icon("ListItemDown"), &amp;lt;&amp;lt; Set Tip("Move selection down")),
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think you can do drag and drop using Mouse Box, but I prefer buttons in JMP (much easier to create)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: &lt;LI-MESSAGE title="MouseBox ListBox Drag and Drop" uid="22698" url="https://community.jmp.com/t5/JMP-Scripts/MouseBox-ListBox-Drag-and-Drop/m-p/22698#U22698" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-tkb-thread lia-fa-icon lia-fa-tkb lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp; has a bit more discussion, such as craige_hales saying that attempting to use Mouse Box wouldn't most likely be very robust solution and suggests using buttons.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2024 07:01:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Reordering-a-list-box/m-p/737152#M91814</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2024-03-22T07:01:05Z</dc:date>
    </item>
  </channel>
</rss>

