Buscando elementos en el cuadro de listaMe gustaría saber si existe una manera fácil de encontrar elementos en la GUI que tenga un cuadro de lista.
Algo así como el filtro de búsqueda de columnas pero para un Listbox.
Modelado estadístico avanzadoInvestigación de Consumidores y MercadosOrganización de contenidosCombinación y limpieza de datosExploración y visualización de datosRe: Buscando elementos en el listboxCómo construyo estos cambios caso por caso, pero usar Filter Col Selector es bastante simple (normalmente no tengo que preocuparme por las tablas privadas, pero no conozco su caso de uso, así que hice algunos trucos para ellas)
Names Default To Here(1);
create_filter = function({items}, {Default Local},
dt = New Table("",
New Column("a", Character, Values(items)),
private
);
dt_split = dt << 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, << 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)
)
);
También puede usar V List Box y compilarlo usando Text Edit Box (desea almacenar la lista original en algún lugar)
Names Default To Here(1);
create_filter = function({items}, {Default Local},
Eval(EvalExpr(
vlb = V List Box(
Text Edit Box("", <<SET text="" changed=""></SET>
y también existen otros métodos según la aplicación y el caso de uso.
Re: Buscando elementos en el listboxHola, gracias por la solución pero no funciona cuando tenemos varios listbox en una misma ventana. Me podría ayudar ? Me gustaría tener una función genérica para reemplazar la función nativa listbox() con dicho filtro. Probé con {DefaultLocal} en mi función, pero no funciona. Me gustaría agregar un argumento a la función filter_items() pero no puedo. ¿Dónde me equivoco?
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 <= 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 << 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("",
<< set width(300),
// The filter_items function does the work
<< set text changed(filter_items )
),
reset_button =
button box("",
<< set icon("DebuggerDeleteBreakpoint"),
<< set script(
// Clear the filter and call the callback function
item_search_teb << set text("");
filter_items(item_search_teb, "");
),
<< 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 )
)
); Re: Buscando elementos en el listbox¡Lindo! No sabía acerca de '' << setTextChanged()'.
Re: Buscando elementos en el listboxEsta solución actualizará el cuadro de lista con cada carácter que escriba.Justin Chilton me lo mostró por primera vez.
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 <= 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 << 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("",
<< set width(300),
// The filter_items function does the work
<< set text changed(filter_items)),
reset_button = button box("",
<< set icon("DebuggerDeleteBreakpoint"),
<< set script(
// Clear the filter and call the callback function
item_search_teb << set text("");
filter_items(item_search_teb, "");
),
<< set tip("Clear filter"),
),
),
panelbox("Select a state:",
item_disp_box = listbox(item_list, width(200), nlines(10)),
),
)


Re: Buscando elementos en el listboxSobre la base de @txnelson pensamientos:
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("", << setScript(updateLB), << setWidth(200)),
lb = List Box(lbi, << setWidth(200))
)
);
updateLB =
Expr(
txt = teb << getText;
lbiNew = lbi;
if(txt != "",
// Remove non-matching items according to some logic
for(i = NItems(lbi), i>= 1, i--, if(!StartsWith(lbi[i], txt), RemoveFrom(lbiNew, i)));
);
// Set new items
lb << setItems(lbiNew);
);
Re: Buscando elementos en el listboxGracias. Busco un cuadro de texto interactivo. Por ejemplo, cuando escribe "Seg", la lista elimina elementos y muestra solo "Segundo elemento".Re: Buscando elementos en el listboxA continuación se muestra un ejemplo sencillo de una búsqueda en un cuadro de lista().
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<<GET items=""></GET>
Si puede proporcionar más detalles, es posible que haya disponible una respuesta más exacta.