<?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 Re: Searching elements in listbox in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/690036#M87595</link>
    <description>&lt;P&gt;How I build these changes case by case, but using Filter Col Selector is fairly simple (usually I don't have to worry about the private tables, but I don't know your use case, so I did some trickery for them)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

create_filter = function({items}, {Default Local},
	dt = New Table("",
		New Column("a", Character, Values(items)),
		private
	);

	dt_split = dt &amp;lt;&amp;lt; Split(
		Split By(:a),
		Split(:a),
		Output Table("temp"),
		Sort by Column Property,
		private 
	);
	Close(dt, no save);
	Eval(EvalExpr(
		fcs = Filter Col Selector(dt_split,  &amp;lt;&amp;lt; Set Script(
			Expr(dt_split); // not sure how robust this will be, used to store the private table reference
		));	
	));
	return(fcs);
);

item_list1 = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota"};

item_list2 = {"Mississippi", "Missouri", "Montana", "Nebraska",
"Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas",
"Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};

nw = New Window("demo",
	H List Box(
		a = create_filter(item_list1),
		b = create_filter(item_list2)
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also use V List Box and build it using Text Edit Box (you want to store the original list somewhere)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

create_filter = function({items}, {Default Local},
	Eval(EvalExpr(
			vlb = V List Box(
			Text Edit Box("", &amp;lt;&amp;lt;Set Text Changed(Function({this, value},
				all_items = Expr(items);
				new_list = Filter Each({name}, all_items, Contains(lowercase(name), lowercase(value)));
				If(N Items(new_list) == 0 &amp;amp; IsMissing(value),
					new_list = all_items;
				);
				(this &amp;lt;&amp;lt; sib) &amp;lt;&amp;lt; set items(new_list)
			))),
			List Box(items)
		);
	));
	
	return(vlb);
);

item_list1 = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota"};

item_list2 = {"Mississippi", "Missouri", "Montana", "Nebraska",
"Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas",
"Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};

nw = New Window("demo",
	H List Box(
		vlb1 = create_filter(item_list1),
		vlb2 = create_filter(item_list2)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and there are also other methods depending on the application and use case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Oct 2023 17:27:10 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2023-10-24T17:27:10Z</dc:date>
    <item>
      <title>Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380361#M63074</link>
      <description>&lt;P&gt;I would like to know if there is an easy way to find elements in GUI having a Listbox.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like the column search filter but for a Listbox.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 19:45:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380361#M63074</guid>
      <dc:creator>FN</dc:creator>
      <dc:date>2023-06-09T19:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380364#M63075</link>
      <description>&lt;P&gt;Here is a simple example of a search in a List Box().&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
New Window( "Example",
	fontobj = lb = List Box(
		{"First Item", "Second Item", "Third Item"},
		width( 200 ),
		max selected( 2 ),
		nlines( 6 )
	)
);
show(contains(lb&amp;lt;&amp;lt;get items,"Second Item"))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you can provide more details, a more exacting answer may be available&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 10:16:12 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380364#M63075</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-04-28T10:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380370#M63077</link>
      <description>Thanks. I am after an interactive text box. For example, when you type "Sec" the list removes elements and shows only "Second Item".</description>
      <pubDate>Wed, 28 Apr 2021 11:12:26 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380370#M63077</guid>
      <dc:creator>FN</dc:creator>
      <dc:date>2021-04-28T11:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380375#M63078</link>
      <description>&lt;P&gt;Building on&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;thoughts:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;NamesDefaultToHere(1);

lbi = {"First Item", "Second Item", "Second Item Duplicate", "Third Item"};

New Window( "Searchable List Box",
	PanelBox("Type in the box below and hit Enter to select matching list items",
			teb = TextEditBox("", &amp;lt;&amp;lt; setScript(updateLB), &amp;lt;&amp;lt; setWidth(200)),
			lb = List Box(lbi, &amp;lt;&amp;lt; setWidth(200))
			)
	);

updateLB =
Expr(
	txt = teb &amp;lt;&amp;lt; getText;
	lbiNew = lbi;
	if(txt != "",
		// Remove non-matching items according to some logic
		for(i = NItems(lbi), i&amp;gt;= 1, i--, if(!StartsWith(lbi[i], txt), RemoveFrom(lbiNew, i)));
		);
	// Set new items
	lb &amp;lt;&amp;lt; setItems(lbiNew);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Apr 2021 12:37:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380375#M63078</guid>
      <dc:creator>ian_jmp</dc:creator>
      <dc:date>2021-04-28T12:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380392#M63079</link>
      <description>&lt;P&gt;This solution will update the listbox with every character you type.&amp;nbsp; First shown to me by Justin Chilton.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;filter_items = Function( {this, searchText},
	{filtered_items, i},
	// only attempt to filter if there is any text
	If( searchText != "",
		// new list for groups that match searchText
		filtered_items = {};
		// Check if each group matches the given text
		For( i = 1, i &amp;lt;= N Items( item_list ), i++,
			// Insert to our list if it contains our search text (case insensitive)
			If( Contains( Lowercase( item_list[i] ), Lowercase( searchText ) ),
				Insert Into( filtered_items, item_list[i] );
			)
		);
		,
	// else show all groups
		filtered_items = item_list;
	);
	item_disp_box &amp;lt;&amp;lt; Set Items( filtered_items );
);		// end filter_items function

item_list = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", "Nebraska",
"Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas",
"Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};

nw = new window("Demonstrate Listbox Search",
	hlistbox(
		icon box("SearchIndex"),
		spacer box(size(5, 10)),
		item_search_teb = text edit box("", 
				&amp;lt;&amp;lt; set width(300),
// The filter_items function does the work
				&amp;lt;&amp;lt; set text changed(filter_items)),
		reset_button = button box("", 
				&amp;lt;&amp;lt; set icon("DebuggerDeleteBreakpoint"),
				&amp;lt;&amp;lt; set script(
// Clear the filter and call the callback function
				item_search_teb &amp;lt;&amp;lt; set text("");
				filter_items(item_search_teb, "");
				),
				&amp;lt;&amp;lt; set tip("Clear filter"),
		),
	),
	panelbox("Select a state:",
		item_disp_box = listbox(item_list, width(200), nlines(10)),
	),
)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pmroz_0-1619614212375.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32385i0B0E2E15BEA49FBA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pmroz_0-1619614212375.png" alt="pmroz_0-1619614212375.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pmroz_1-1619614242680.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/32386i0C0C796C9FB2105A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pmroz_1-1619614242680.png" alt="pmroz_1-1619614242680.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Apr 2021 12:51:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380392#M63079</guid>
      <dc:creator>pmroz</dc:creator>
      <dc:date>2021-04-28T12:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380777#M63118</link>
      <description>&lt;P&gt;Nice! I didn't know about '' &amp;lt;&amp;lt; setTextChanged()'.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Apr 2021 08:47:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/380777#M63118</guid>
      <dc:creator>ian_jmp</dc:creator>
      <dc:date>2021-04-29T08:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/689908#M87588</link>
      <description>&lt;P&gt;Hello, thanks for the solution but it doesn't work when we have several listboxes in the same window. Could you please help me ? I would like to have a generic function to replace listbox() native function with such a filter. I tried with {DefaultLocal} into my function, but it doesn't work. I would like to add an argument to the filter_items() function but I can't. Where am I wrong ?&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;filter_items = Function( {this, searchText},
	{filtered_items, i},
	// only attempt to filter if there is any text
	If( searchText != "",
		// new list for groups that match searchText
		filtered_items = {};
		// Check if each group matches the given text
		For( i = 1, i &amp;lt;= N Items( item_list ), i++,
			// Insert to our list if it contains our search text (case insensitive)
			If( Contains( Lowercase( item_list[i] ), Lowercase( searchText ) ),
				Insert Into( filtered_items, item_list[i] );
			)
		);
		,
	// else show all groups
		filtered_items = item_list;
	);
	item_disp_box &amp;lt;&amp;lt; Set Items( filtered_items );
);		// end filter_items function

listbox_with_filter = Function( {item},
	listbox = 
	vlistbox(
		hlistbox(
			icon box("SearchIndex"),
			spacer box(size(5, 10)),
			item_search_teb = 
				text edit box("", 
					&amp;lt;&amp;lt; set width(300),
					// The filter_items function does the work
					&amp;lt;&amp;lt; set text changed(filter_items )
				),
			reset_button = 
				button box("", 
					&amp;lt;&amp;lt; set icon("DebuggerDeleteBreakpoint"),
					&amp;lt;&amp;lt; set script(
						// Clear the filter and call the callback function
						item_search_teb &amp;lt;&amp;lt; set text("");
						filter_items(item_search_teb, "");
					),
					&amp;lt;&amp;lt; set tip("Clear filter"),
				),
		),
		panelbox("Select a state:",
			item_disp_box = listbox(item, width(200), nlines(10)),
		)
	);
	return( listbox );
);

item_list1 = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota"};

item_list2 = {"Mississippi", "Missouri", "Montana", "Nebraska",
"Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas",
"Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};

nw = new window("Two Listbox Search",
	HListBox(
		listbox_with_filter( item_list1 )
	,
		listbox_with_filter( item_list2 )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 24 Oct 2023 13:55:19 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/689908#M87588</guid>
      <dc:creator>carole</dc:creator>
      <dc:date>2023-10-24T13:55:19Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/690036#M87595</link>
      <description>&lt;P&gt;How I build these changes case by case, but using Filter Col Selector is fairly simple (usually I don't have to worry about the private tables, but I don't know your use case, so I did some trickery for them)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

create_filter = function({items}, {Default Local},
	dt = New Table("",
		New Column("a", Character, Values(items)),
		private
	);

	dt_split = dt &amp;lt;&amp;lt; Split(
		Split By(:a),
		Split(:a),
		Output Table("temp"),
		Sort by Column Property,
		private 
	);
	Close(dt, no save);
	Eval(EvalExpr(
		fcs = Filter Col Selector(dt_split,  &amp;lt;&amp;lt; Set Script(
			Expr(dt_split); // not sure how robust this will be, used to store the private table reference
		));	
	));
	return(fcs);
);

item_list1 = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota"};

item_list2 = {"Mississippi", "Missouri", "Montana", "Nebraska",
"Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas",
"Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};

nw = New Window("demo",
	H List Box(
		a = create_filter(item_list1),
		b = create_filter(item_list2)
	)
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can also use V List Box and build it using Text Edit Box (you want to store the original list somewhere)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

create_filter = function({items}, {Default Local},
	Eval(EvalExpr(
			vlb = V List Box(
			Text Edit Box("", &amp;lt;&amp;lt;Set Text Changed(Function({this, value},
				all_items = Expr(items);
				new_list = Filter Each({name}, all_items, Contains(lowercase(name), lowercase(value)));
				If(N Items(new_list) == 0 &amp;amp; IsMissing(value),
					new_list = all_items;
				);
				(this &amp;lt;&amp;lt; sib) &amp;lt;&amp;lt; set items(new_list)
			))),
			List Box(items)
		);
	));
	
	return(vlb);
);

item_list1 = {"Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware", "Florida",
"Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota"};

item_list2 = {"Mississippi", "Missouri", "Montana", "Nebraska",
"Nevada", "New Hampshire", "New Jersey", "New Mexico", "New York", "North Carolina", "North Dakota", "Ohio",
"Oklahoma", "Oregon", "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas",
"Utah", "Vermont", "Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"};

nw = New Window("demo",
	H List Box(
		vlb1 = create_filter(item_list1),
		vlb2 = create_filter(item_list2)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and there are also other methods depending on the application and use case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Oct 2023 17:27:10 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/690036#M87595</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-10-24T17:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/690095#M87601</link>
      <description>&lt;P&gt;With a Combo Box you can combine both feature in one Display Box - a freely editable text edit box and a list which&amp;nbsp;is linked to it:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_0-1698172932450.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57932i7E27A070B722FEAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_0-1698172932450.png" alt="hogi_0-1698172932450.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;suggestions={"some","values","to","pick"};

new window("test", cb = Combo Box( suggestions, editable,&amp;lt;&amp;lt;Set Width( 300 ) ))&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Oct 2023 18:44:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/690095#M87601</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2023-10-24T18:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Searching elements in listbox</title>
      <link>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/695188#M88031</link>
      <description>&lt;P&gt;Thank you very much for the two solutions !&lt;/P&gt;&lt;P&gt;I prefer the one with texteditbox because when we have lots of listboxes, I am afraid about the high number of private tables that won't be closed (memory charge).&lt;/P&gt;&lt;P&gt;Thanks a lot it's perfect for me the second solution;&lt;/P&gt;&lt;P&gt;Carole&lt;/P&gt;</description>
      <pubDate>Tue, 07 Nov 2023 14:09:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Searching-elements-in-listbox/m-p/695188#M88031</guid>
      <dc:creator>carole</dc:creator>
      <dc:date>2023-11-07T14:09:03Z</dc:date>
    </item>
  </channel>
</rss>

