combobox first item show when populated
Hi ,
I have this combobox that is being populated form a table. This Ive done , now I need it to have a specific item show as default. Since the combobox needs to be indexed, how can I code it to show always this specific item.
I tried to have
MyCombobox.GetItemText = "MyItemText"
but does not work. Any help please. Thanks
Re: combobox first item show when populated
Try this... the items are objects.. if they are strings, just cast them..
VB Code:
Dim mytest As String
mytest = DirectCast(ComboBox1.Items.Item(0), String) '0 is first item...
Re: combobox first item show when populated
K.. if you just want to select the item... then just call the selectedindex..
VB Code:
ComboBox1.SelectedIndex = 0 'selects the first item in the collection
Re: combobox first item show when populated
How have you populated this ComboBox? The most likely ways to select your default value would be to set the SelectedIndex, SelectedItem or SelectedValue property. Which one you use would depend on how you've populated the list and how you can identify the default value.
Re: combobox first item show when populated
hi,
Still not loading first item. What I am doing is to populate the combobox from database which loads data except that the first item is not showing up. It is getting them sorted so obviously the first one that was entered is not showing up.
I dont know why cos the field is not indexed and the combobox properties's sorted is set to false. Any ideas why.