Binding the Combobox SelectedValue to a textbox

I also have TextBox

a ComboBox

. I want to associate ComboBox

selected value with text in TextBox

.

Please, help.

thank

+2


source to share


2 answers


<ComboBox x:Name="MyComboBox">
  <ComboBoxItem>12</ComboBoxItem>
  <ComboBoxItem>13</ComboBoxItem>
  <ComboBoxItem>14</ComboBoxItem>
  <ComboBoxItem>15</ComboBoxItem>
</ComboBox>
<TextBox Text="{Binding Path=SelectedValue.Content, ElementName=MyComboBox}" />

      



Since the elements in ComboBox

are of type ComboBoxItem

, I used the property Content

to get the real value. You must use any property exposed by the objects in ComboBox

(use nothing if it is already a list of strings).

+8


source


This is for a list box, not a combobox, but it should be roughly the same code:

private void *lstProducts*_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    *currentlabel*.Content = *lstProducts*.SelectedValue.ToString();
}

      



The cursed bits are the names of the control.

Hope it helps ...

-1


source







All Articles