populating the dropdown with hard coded values

How can I populate my combobox with hard coded values. Please note that what I will display in the selection list is also the value i.e 1 is really 1 and not some value1.
Please include any other steps I have to take like opening the datasource etc as well.

Thanks
LuckyLucksAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hatem72Commented:

   Public Function FillCombo(ByRef cBox As Object, ByVal Tbl As String, ByVal IdFld As String, ByVal NameFld As String, ByVal SqsString As String) As String


        Try
            ' cBox ur ComboBox    
            ' v_ConnectionString Connection String
            ' Tbl  ur table ( Or View ) name
            ' IdFld  DisplayMember Field
            ' NameFld DisplayMember Field
            ' SqsString Select statment

            Dim Conn As SqlConnection = New SqlConnection(v_ConnectionString)
            Dim Comm As SqlCommand = New SqlCommand(SqsString, Conn)
            Comm.Connection = Conn
            Comm.CommandText = SqsString ' "commandtorun"
            Comm.CommandType = CommandType.Text
            Dim DS As DataSet = New DataSet()

            Dim DA As New SqlDataAdapter(Comm)
            Conn.Open()
            DA.Fill(DS, Tbl)

            Dim dt As New DataTable
            dt.Columns.Add(NameFld, GetType(System.String))
            dt.Columns.Add(IdFld, GetType(System.String))

            With cBox
                .DataSource = DS.Tables(Tbl)    'dt
                .DisplayMember = NameFld
                .IdFld = IdFld
            End With


            Call ClossConn(Conn) ' Closs Current Connection

            Return 0
        Catch ex As Exception

            Return ex.Message

        End Try
    End Function
0
LuckyLucksAuthor Commented:
querying the database indicates populating the dropdown with dymanic data. I dont have an underlying table. I need a simple drop down for 3 predefined values.

Thanks
0
SanclerCommented:
1)  In design view you can add harcoded items to the combo by selecting the control and then, in the properties window, clicking on the button under "Items" and typing them in the pane that appears.

2)  In code, you can use

    myCombo.Items.Add("Item1")
    'etc

or

        Dim myArray(2) As String
        myArray(0) = "ItemA"
        myArray(1) = "ItemB"
        myArray(2) = "ItemC"
        ComboBox1.Items.AddRange(myArray)

Roger
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

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.