Emad Shojaeenasab
Emad Shojaeenasab

Reputation: 29

how can i get value from combo box and show it to textbox

how can show value of selected item in combobox in textblock ?

i use this code to get value .

  combobox20.ItemsSource = database.Mavads.ToList();
            combobox20.DisplayMemberPath = "MavadName";
            combobox20.SelectedValuePath = "MavadFe";

I try to get it with this code

txt_f1.Text = combobox1.SelectedValuePath ;

but show me "MavadFe"

i use event "IsMouseCapturedChanged"

Upvotes: 2

Views: 73

Answers (2)

Grant Winney
Grant Winney

Reputation: 66499

The SelectedValuePath sets the field used to represent whatever item you've selected, but to get the actual selected value you need SelectedValue. It's an object, so assuming the "MavadFe" field is a string, just convert it.

private void combobox20_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    txt_f1.Text = combobox1.SelectedValue.ToString();
}

Upvotes: 2

Vikas Thombre
Vikas Thombre

Reputation: 50

comboBox1.SelectedItem.ToString();

Upvotes: -1

Related Questions