Click here to Skip to main content
15,920,513 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a desktop application, and I have a situation where I pass a value member and a display member to a combobox. Now when I click a combobox I want the value member to show on one text box and the display member on the another text box. How can I do that? So far my code looks like these

VB
Dim ds As New DataSet
        Dim da As New SqlDataAdapter
        Dim cmd As New SqlCommand

        cmd.CommandText = "[AP249_Falsifikati].[ProcGetDostavuvaci]"
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Connection = con

        cmd.Parameters.AddWithValue("@TipDostavuvac", TipDostavuvac)
        cmd.Parameters.AddWithValue("@Datum", DatumPrimanje)

        da.SelectCommand = cmd
        da.Fill(ds, "Tabela")


        cmbDostavuvaci.Visible = True
        cmbDostavuvaci.DataSource = ds.Tables(0).DefaultView
        cmbDostavuvaci.ValueMember = "MatBR"
        cmbDostavuvaci.DisplayMember = "Naziv"
Posted
Updated 23-Sep-13 23:02pm
v3

As i understand from your code, in this way you fill the combobox.
And know you want put the selected value in textbox.
in c# it will be:
String s = cmbDostavuvaci.SelectedItem.ToString();
 
Share this answer
 
v2
Comments
Voley 25-Sep-13 3:32am    
Thnx these was helpfull
Diana Tsax 25-Sep-13 3:57am    
You are welcome!
Hello,

Since you are saying that you want to show the value member and display member in the textboxes upon click of the combobox. You can use ComboBox.OnSelectedIndexChanged[^] Method to accomplish this. The following code snippet shows this.
C#
private void cmbDostavuvaci_OnSelectedIndexChanged(Object sender, EventArgs e) {
    txtValue.Text = cmbDostavuvaci.SelectedValue.ToString();
    txtDisplay.Text = cmbDostavuvaci.SelectedText;
}

A detailed example can be found here[^].

Regards,
 
Share this answer
 
Comments
Voley 25-Sep-13 3:33am    
Thank you this is exactly what I wanted :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900