cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
miguello
Level VI

Why can't I have duplicate values in List Box?

If I run this:

lb = List Box({"qwerqwerr", "qwerqwerr"});

nwTest = New Window("Test ListBox Duplicate values", lb);

I will get a List Box with only one line. Why?

List Box accepts lists, lists can have duplicate values, why can't Lis Box have duplicate values?

If I pass a list with duplicate values to List Box, what's shown in the List Box is not the list that was passed with now additional warnings or errors.

IS it by design? Why? Any workarounds?

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Why can't I have duplicate values in List Box?

I agree that the documentation should point out that the list box will use unique items in the list provided. The list argument does not need to have unique items. Anyone using the documentation should be prepared; that is to say, any possible behavior is expected.

 

So even if your examples are hypothetical, the choice of an object depends on its purpose. Here are two approaches based on your example of displaying a list of steps, which might not be unique over the entire path. One method uses a direct update, and the other uses a list of steps for persistence. (The first approach could get the list from the string column box, if necessary.)

 

Names Default to Here( 1 );

// directly update list of steps
New Window( "Move It 1",
	H List Box(
		Outline Box( "Control",
			Line Up Box( N Col( 3 ),
				Text Box( "" ),
				Button Box( "Up",
					scb << Add Element( "Up" )
				),
				Text Box( "" ),
				Button Box( "Left",
					scb << Add Element( "Left" )
				),
				Text Box( "" ),
				Button Box( "Right",
					scb << Add Element( "Right" )
				),
,
				Text Box( "" ),
				Button Box( "Down",
					scb << Add Element( "Down" )
				),
				Text Box( "" )
			)
		),
		Outline Box( "Path",
			Table Box(
				scb = String Col Box( "Step", {} )
			)
		)
	)
);

//use list as an intermediary structure
updatePath = Function( { list, text, obj },
	Insert Into( list, Eval( text ) );
	obj << Set( list );
	Return( list );
);
path = List();
New Window( "Move It 2",
	H List Box(
		Outline Box( "Control",
			Line Up Box( N Col( 3 ),
				Text Box( "" ),
				Button Box( "Up",
					path = updatePath( path, "Up", scb );
				),
				Text Box( "" ),
				Button Box( "Left",
					path = updatePath( path, "Left", scb );
				),
				Text Box( "" ),
				Button Box( "Right",
					path = updatePath( path, "Right", scb );
				),
				Text Box( "" ),
				Button Box( "Down",
					path = updatePath( path, "Down", scb );
				),
				Text Box( "" )
			)
		),
		Outline Box( "Path",
			Table Box(
				scb = String Col Box( "Step", path )
			)
		)
	)
);

View solution in original post

11 REPLIES 11
txnelson
Super User

Re: Why can't I have duplicate values in List Box?

I have not found documentation specifying that only a unique list of values are displayed in a List Box, but in my testing of it, it does appear that only a single entry is displayed for each specific value in the list box associated with the List Box() object..

Jim

Re: Why can't I have duplicate values in List Box?

The List Box is intended to present items for selection in the user interface. You only pointed out the behavior of this object. How would a user know which item they want if they have the same value? Perhaps another display box would serve your purpose, which you have not shared.

David_Burnham
Super User (Alumni)

Re: Why can't I have duplicate values in List Box?

As @Mark_Bailey indicated, the list box is behaving this way by design.  

 

The list box is designed as a user-interface element to allow a user to select a value from a list e.g {"ImpurityA","ImpurityB","ImpurityC","ImpurityD"}.  If you present a list such as {"ImpurityA","ImpurityB","ImpurityC","ImpurityD","ImpurityB"} how would the user know whether to select the 1st of 2nd "ImpurityB".  Logically the user should be presented with a unique list of values and that is what the List Box does.

 

But I'm sympathetic to the question because I commonly use a ListBox as a scrolling log into which I write messages.  Which then causes problems if I want to write a line into the log which has already been written, because I can't have the same line twice.  In this use-case I usually resort to maintaining a string message with line breaks, and display the string using a multi-line Text Box.

 

If the use-case is to allow a user to make a selection then presumably there is secondary information that distinguishes between the two ImpurityB's in the above example, in which case you can build a list of composite items to be displayed in the List Box:

{"ImpurityA/Batch1",ImpurityB/Batch1", ...,  "Impurity B/Batch2"}

-Dave
miguello
Level VI

Re: Why can't I have duplicate values in List Box?

@David_Burnham , @Mark_Bailey and @txnelson 

My point is two-fold: 

1. If it accepts lists as input - it should not alter it and display as is. Basically, it is not a good behavior when the control doesn't show what was fed into it. If it needs to be unique - don't allow lists, make it associative arrays where keys are lines, values are either ignored or are something else. Or at least throw some kind of a warning or exception when list with duplicate values are provided as input.

 

2. How to distinguish between identical values? Well, there is order in the list, right? I can come up with many use cases where user would use this kind of control to reflect steps in algorithm, sets of identical objects that user assembled, reports to run etc.

For instance, I have four buttons: "Left", "Right", "Up" and "Down". User needs to set up some algorithm to achieve a certain result. He programs this by pressing buttons consecutively. Each press of a button adds a step into a list. Making a list of steps. This list contains identical steps. Right, right, up, right, down, down, left. This is a list. Where would I display such a list, if not in something that is called List Box()?

Re: Why can't I have duplicate values in List Box?

1. A list box is not a list. It does not have the exact expectations or interface as a data structure. It is interactive, two-way communication. An associative array would solve 'the problem.' Many users are not familiar or comfortable with these structures but find a list natural to work with. The list is merely an argument to provide the necessary data for the list box to perform its function. Conveniently, duplicates are automatically discarded.

 

2. Given that the list box is an object to present a list of unique choices and facilitates the interaction with the user who needs to select one or more items, it is the wrong choice for a UI component where duplicates arise. You have to choose another object for your purpose. Your use case needs to store an ordered list of selections made elsewhere in the UI. A string column box might be a good choice for this purpose.

miguello
Level VI

Re: Why can't I have duplicate values in List Box?

I understand that List Box is not a list. It's that it accepts lists as an input. Nowhere in the documentation does it say the list need only have unique values. It was an unexpected behavior.

Imagine, for instance, you have a text box, that accepts strings as an input. So it would show this string in a box, unless it starts with letter 'a'.  It just wouldn't show anything if the string starts with 'a'. And it is not documented anywhere. What a bummer for somebody trying to troubleshoot why that text box sometimes empty, right?

Re: Why can't I have duplicate values in List Box?

I agree that the documentation should point out that the list box will use unique items in the list provided. The list argument does not need to have unique items. Anyone using the documentation should be prepared; that is to say, any possible behavior is expected.

 

So even if your examples are hypothetical, the choice of an object depends on its purpose. Here are two approaches based on your example of displaying a list of steps, which might not be unique over the entire path. One method uses a direct update, and the other uses a list of steps for persistence. (The first approach could get the list from the string column box, if necessary.)

 

Names Default to Here( 1 );

// directly update list of steps
New Window( "Move It 1",
	H List Box(
		Outline Box( "Control",
			Line Up Box( N Col( 3 ),
				Text Box( "" ),
				Button Box( "Up",
					scb << Add Element( "Up" )
				),
				Text Box( "" ),
				Button Box( "Left",
					scb << Add Element( "Left" )
				),
				Text Box( "" ),
				Button Box( "Right",
					scb << Add Element( "Right" )
				),
,
				Text Box( "" ),
				Button Box( "Down",
					scb << Add Element( "Down" )
				),
				Text Box( "" )
			)
		),
		Outline Box( "Path",
			Table Box(
				scb = String Col Box( "Step", {} )
			)
		)
	)
);

//use list as an intermediary structure
updatePath = Function( { list, text, obj },
	Insert Into( list, Eval( text ) );
	obj << Set( list );
	Return( list );
);
path = List();
New Window( "Move It 2",
	H List Box(
		Outline Box( "Control",
			Line Up Box( N Col( 3 ),
				Text Box( "" ),
				Button Box( "Up",
					path = updatePath( path, "Up", scb );
				),
				Text Box( "" ),
				Button Box( "Left",
					path = updatePath( path, "Left", scb );
				),
				Text Box( "" ),
				Button Box( "Right",
					path = updatePath( path, "Right", scb );
				),
				Text Box( "" ),
				Button Box( "Down",
					path = updatePath( path, "Down", scb );
				),
				Text Box( "" )
			)
		),
		Outline Box( "Path",
			Table Box(
				scb = String Col Box( "Step", path )
			)
		)
	)
);
miguello
Level VI

Re: Why can't I have duplicate values in List Box?

Understood, thanks!

You should've used different names for "scb" - resulted in a pretty funny behavior the way it is now.

 

Anyways, what control is used here:

2022-11-30 16_48_25-Window.png

 

In my script I used a similar GUI to match two columns, only the whole thing is a little bit more complex, and the second columns may have many auxiliary columns which I don't want to be displayed in "height=height" line. Hence the possibility of duplicate values.

For now I set it up to show as "height=height;sex,name,age" to make everything unique, but ideally I would only want to show main columns. 

Re: Why can't I have duplicate values in List Box?

You said, "You should've used different names for "scb" - resulted in a pretty funny behavior the way it is now." How so?