Select setNullSelectionItemID()

Hello,

I have a question about the select object. From what I have read in the book, select.setNullSelectionItemId(Object item); should set the default(non-selected) value of the drop-down list to that value.

public void init()
{
Window mainWindow = new Window(“Selectingitems Application”);
setMainWindow(mainWindow);
Select select = new Select(“Select something here”);

	select.setNullSelectionItemId(new String("AKDF")); //<------------------ What Am I doing wrong here
	mainWindow.addComponent(select);
	
	
	final String[] planets ={"Mercury" , "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"};
	
	for(int i =0; i < planets.length; i++)
	{
		select.addItem(planets[i]

);
}

}

The code for my program is pasted above. From what I understood, “select.setNullSelectionItemId(new String(“AKDF”));”
should set the default value of the list to AKDF. However, A blank option still shows up as the default value for the select object.

Any help would be really appreciated.

Rohith

Also, How can I make this list into multiple selection Mode?

Thanks,
Rohith

You almost had it, not far from it. There’s just one catch - you have to choose an item from the items in the select to be your “null value”. In other words, you have to add it to your select first.

change this:

select.setNullSelectionItemId(new String("AKDF"));

to this

String myFineAKDFString = new String("AKDF");
select.addItem(myFineAKDFString);
select.setNullSelectionItemId(myFineAKDFString);

multiselect is done by doing this:

select.setMultiSelect(true);

But be vary, you can’t use these two at the same time - setNullSelectionItemId and setMultiSelect(true). It will only lead to that the application won’t start and you’ll get a console message telling you not to do it. After all, in multiselect, choosing no items is the equivalent of null.

Thanks alot.

Rohith