Hi,
I have a textbox and a combobox .I want to bind combobox the selected value to text in the textbox.
Please help.
Thanks
Hi,
I have a textbox and a combobox .I want to bind combobox the selected value to text in the textbox.
Please help.
Thanks
This is for a listbox, not a combobox, but it should be pretty much the same code:
private void *lstProducts*_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
*currentlabel*.Content = *lstProducts*.SelectedValue.ToString();
}
The italicized bits are the names of the control.
Hope it helps...
<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 items in the ComboBox
are of type ComboBoxItem
, I used the Content
property to get the real value. You should use whatever property exposed by the objects in your ComboBox
(use nothing if it already is a list of strings).
@julien I have similar situation. I am having a grid with two columns one having dropdown and another having textbox. Condition is that, if I select some item from the combobox then its value will get set to its respective textbox. I tried above but , no luck..