绑定WPF组合框并将其值显示到TextBox

时间:2021-12-10 16:05:49

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!!

你好朋友我想显示从DB到组合框的数据,DB表有id,investPlan,金额。现在我想在组合框中显示'investPln'col,当用户选择任何计划时,相应的金额将显示在textBox控件中。我能够在comboBox中显示'invetsPlan'行,但不知道如何做休息的事情。帮我!!

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

2 个解决方案

#1


6  

You're almost there!

你快到了!

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

There you go :)

你去:)

#2


0  

Combobox has a event to fire on change of an item .You can use that .SelectionChanged event

Combobox有一个事件可以触发更改项目。您可以使用.SelectionChanged事件

#1


6  

You're almost there!

你快到了!

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

There you go :)

你去:)

#2


0  

Combobox has a event to fire on change of an item .You can use that .SelectionChanged event

Combobox有一个事件可以触发更改项目。您可以使用.SelectionChanged事件