简体   繁体   中英

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"

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();
}

comboBox1.SelectedItem.ToString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM