winform comboBox

I want to assign a text value to the winform combobox and get its value set on click of a button
I want it something like below (When form loads it shows  "Assigned" as selected and when button is clicked it should display 50000. Below code doesnot work

    Me.ComboBox1.DisplayMember = "Assigned"
        Me.ComboBox1.ValueMember = 50000

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

I need to use on of the following properties to programaticallly select a value in a combobox:

The properties DisplayMember and ValueMember are for binding to datasources.
Those two properties are for data source binding. Both properties expect references to datasource field properties, and you wont be able to get the functionality that you are looking for with a standard combobox in that manner.
However, you could use something like:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ComboBox1.Text = "Assigned" Then ComboBox1.Text = 5000
End Sub
To add "Assigned" to your combobox:
To select it :
ComboBox1.SelectedItem = "Assigned"
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

dotnet0824Author Commented:
well its this
i want to assign the  Text to "Assigned" and when its selected I shoul dget the selectedValue as 5000
How can we assign using them using  valuemember properties. Hope the question is clear
This example does what you are talking about. It creates a datatable, populates it with Name/Value pairs, and then binds it to the combobox. When the user selects one of the bound items, a msgbox displays its selectedvalue.
To test it, create a form, add a button and a combobox, and paste it in. If you have any questions let me know.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dt As New DataTable("ValuePairs")
        dt.Columns.Add("Value", GetType(Integer))
        For i = 1 To 10
            Dim nr As DataRow = dt.NewRow
            nr("Name") = "Item " & i
            nr("Value") = i * 16
        With ComboBox1
            .DataSource = dt
            .DisplayMember = "Name"
            .ValueMember = "Value"
        End With
    End Sub
    Private Sub ComboBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.TextChanged
        If IsNumeric(ComboBox1.SelectedValue) Then
        End If
    End Sub

Open in new window


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
dotnet0824Author Commented:
POINT|S INCREASED  Thanks darling .
Actually I am converting a vb code just 3 lines of code to VB.NET Or C#.NET (Any code shown is fine)
   If IsNumeric(Rs1!CustomerID) Then
                    If Rs1!CustomerID = 50000 Then
                        dbcCustomer.BoundText = 50000       In .NET its comboBox
                        dbcCustomer.Text = " Assigned"
                   End If

Can the above example shown by darling made much simpler
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
.NET Programming

From novice to tech pro — start learning today.