开发者

Binding WPF combobox and displaying its Value to TextBox

开发者 https://www.devze.com 2022-12-20 17:45 出处:网络
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 di

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 :)


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

0

精彩评论

暂无评论...
验证码 换一张
取 消