Default Value Drop Down List

Hi,

I have a combo setup as a drop down list, defined the values for the list in the collection, how through the properties do I set the first value to be selected.
LVL 18
PluckaAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
culshajaConnect With a Mentor Commented:
You need to loop through the items and set the slected property iof the item that you want to be selected be set to true.

James :-)
0
 
PluckaAuthor Commented:
Right, if i knew how to do that i'd be half way there :(
0
 
PluckaAuthor Commented:
SpeedCombo.SelectedIndex = 0

works but you got me on the right track.
0
 
culshajaCommented:
Are you using WinForms or ASP.Net?

In Winforms you just use the slectedIndex property i.e.

cboX.SelectedIndex = 2

If you need to loop through it you use the following

        Dim c As Integer
        For c = 1 To cboX.Items.Count - 1
            If CType(cboX.Items(c), String) = myStringVarToCheckAgainst Then
                cboX.SelectedIndex = c
                Exit For
            End If
        Next

In ASP.Net you use the following code:

For intCount = 0 To (objDropDownList.Items.Count - 1)
    If objDropDownList.Items(intCount).Value = myVarToCheckAgainstThen
        objDropDownList.Items(intCount).Selected = True
        Exit For
    End If
Next intCount

Hope this helps

James :-)
0
 
culshajaCommented:
Sorry about being a little late on the better response .....  :-(

James  :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.