[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

populating the dropdown with hard coded values

Posted on 2006-04-24
3
Medium Priority
?
192 Views
Last Modified: 2010-04-23
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
0
Comment
Question by:LuckyLucks
3 Comments
 
LVL 6

Expert Comment

by:hatem72
ID: 16529367

   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
 

Author Comment

by:LuckyLucks
ID: 16536443
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
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 16536761
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question