PDA

View Full Version : [CLOSED] Select the firt item in a ComboBox?



JonathanCR
Sep 26, 2014, 7:01 PM
I have the following Combobox and I need the first item to be selected:


X.ComboBox()
.ID("yearComboBox")
.Editable(false)
.Flex(1)
.FieldLabel("Year")
.QueryMode(DataLoadMode.Local)
.TriggerAction(TriggerAction.All)

)
.Items(
items =>
{
for (int i = DateTime.Today.Year; i > DateTime.Today.Year - 10; i--)
{
var yearItem = new ListItem(i.ToString());
items.Add(yearItem);
}
}
)

I don't want to use
.SelectedItems(new ListItem("2014")) because obviously this is not going to work in the future.

Isn't there a easy way to select the first item using the Index of the item????

Vladimir
Sep 26, 2014, 7:33 PM
Hi

Please use that code


.SelectedItems(new ListItem{ Index = 0 })

JonathanCR
Sep 26, 2014, 8:18 PM
Great, thanks.