How to bind a value from ComboBox to TextBox? RRS feed

  • Question

  • How to bind selected item from the combo box to TextBox?
    Saturday, June 19, 2010 1:20 PM


All replies

  •  <StackPanel>
        <ComboBox Name="combo" SelectedIndex="0">
          <TextBox Text="Item1"></TextBox>
          <TextBox Text="Item2"></TextBox>
          <TextBox Text="Item3"></TextBox>
          <TextBox Text="Item4"></TextBox>
        <TextBox Grid.Row="1" Text="{Binding ElementName=combo,Path=SelectedItem.Text}"/>

    - Jegan
    • Proposed as answer by Jegan Ravi Saturday, June 19, 2010 2:27 PM
    Saturday, June 19, 2010 1:29 PM
  • helo David, please try this


    <ComboBox Height="34"  SelectionChanged="comboBox1_SelectionChanged" Name="comboBox1"

                      VerticalAlignment="Top" >

                <ComboBoxItem >Item1</ComboBoxItem>

                <ComboBoxItem >Item2</ComboBoxItem>

                <ComboBoxItem >Item3</ComboBoxItem>


            <TextBox Height="31"  Name="textBox1" VerticalAlignment="Top" />


    private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)


                textBox1.Text = comboBox1.SelectionBoxItem.ToString();



    Saturday, June 19, 2010 1:34 PM
  • Hi David


    If you want binding in xaml then please write code as following


    <ComboBox Height="34" Margin="52,25,20,0"  Name="comboBox1"

                      VerticalAlignment="Top" >

                <ComboBoxItem >Item1</ComboBoxItem>

                <ComboBoxItem >Item2</ComboBoxItem>

                <ComboBoxItem >Item3</ComboBoxItem>


            <TextBox Height="31" Text="{Binding ElementName=comboBox1,Path=SelectionBoxItem, Mode=OneWay}" Margin="54,93,22,0" Name="textBox1" VerticalAlignment="Top" />



    Saturday, June 19, 2010 1:42 PM
  • Hi ,

    Thanks for your update.

    My attempt is . I am having the ComboxBoxItem. I should bind the selected comboboxitem to the Textbox through Textbox.Text={Binding...from comboboxitem}. How can i achieve this?

    Anyone can you help me please.

    Kinds and Regards,

    David C

    Saturday, June 19, 2010 1:44 PM
  • helo david,

    <TextBox Height="31" Text="{Binding ElementName=comboBox1,Path=SelectionBoxItem, Mode=OneWay}" >

    "comboBox1" is my combobox of which selected item i want to bind to textbox.text property.



    Saturday, June 19, 2010 1:53 PM
  • Hi zahid,

    Thanks a lot...! I got the answer by your method..


    David C

    Saturday, June 19, 2010 1:57 PM
  • please vote if you got the answer



    Saturday, June 19, 2010 2:00 PM