简体   繁体   中英

Binding WPF combobox and displaying its Value to TextBox

Hello friends i want to display data from DB to combobox, DB table has id, investPlan, amount. Now i want to show 'investPln' col in combobox and when user selects any plan then respective amount displays in textBox control. I am able to display 'invetsPlan' rows in comboBox but don't know how to do rest thing. HELP ME!!

XAML Part

<ComboBox Height="23" Margin="70,72,88,0" Name="comboBox1" VerticalAlignment="Top" DropDownClosed="comboBox1_DropDownClosed" 
              ItemsSource="{Binding}" IsSynchronizedWithCurrentItem="True" SelectedValue="{Binding Path=id}" DisplayMemberPath="fullName" SelectedValuePath="id"/>

Code Behind Part

private void Window_Loaded(object sender, RoutedEventArgs e)
    {
        DataSet1TableAdapters.membersTableAdapter ta = new ComboBoxDB.DataSet1TableAdapters.membersTableAdapter();
        comboBox1.ItemsSource = ta.GetData();
    }

You're almost there!

<TextBox Text="{Binding ElementName=comboBox1, Path=SelectedItem.amount}" />

There you go :)

组合框有一个可在更改项目时触发的事件。您可以使用该.SelectionChanged事件

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