Header Ad

Tuesday, May 22, 2012

GWT ListBox with auto-select or pre select option.

The following is the sample example for auto selecting a one of the value in GWT List Box.

List lstValues = new ArrayList();
lstValues.add("Value 1");
lstValues.add("Value 2");
lstValues.add("Value 3");
lstValues.add("Value 4");


ListBox lstBox = new ListBox();
for(int i=0;i<lstValues.size();i++)
{
lstBox.addItem(lstValues.get(i));
}

Suppose, if we want to auto-select the GWT List Box with "Value 2", we can do this by the following code

lstBox.setSelectedIndex(1);

This will automatically, select the "Value 2" option of the ListBox.

No comments: