问题描述
我有一个工作人员表和一个工作人员表
i have a staff table and a staffmember table
Tbl_Staff :
Tbl_Staff:
ID
Id
员工
Staff
Tbl_StaffMembers :
Tbl_StaffMembers:
ID
Id
名字
FirstName
员工
Staff
我正在尝试将 ComboBox ItemsSource = Tbl_Staff
I am trying to bind the ComboBox ItemsSource = Tbl_Staff
并且 SelectedValue =行类型为 Tbl_StaffMembers.staff ...
and SelectedValue =to a row type of Tbl_StaffMembers.staff...
这是我的代码,我设法填充了ItemsSource,但是在将selectedvalue绑定到职员行时遇到了问题
this is my code, i managed to fill the ItemsSource but im having problems with binding the selectedvalue to the staffmember row
//将数据绑定到组合框.
//Binding the data to the combobox.
CmbBStaff.DataContext = dTblStaff;//ds.Tables ["Category"].DefaultView;
CmbBStaff.DataContext = dTblStaff;// ds.Tables["Category"].DefaultView;
CmbBStaff.DisplayMemberPath = dTblStaff.Columns ["Staff"].ToString();
CmbBStaff.DisplayMemberPath = dTblStaff.Columns["Staff"].ToString();
CmbBStaff.SelectedValuePath = dTblStaff.Columns ["Id"].ToString();
CmbBStaff.SelectedValuePath = dTblStaff.Columns["Id"].ToString();
xml:
xml:
< ComboBox Grid.Column ="1" Grid.Row ="3".高度="23". HorizontalAlignment =左"保证金="6".名称="CmbBStaff". VerticalAlignment =顶部"宽度="170". ItemsSource ="{Binding}"/>
<ComboBox Grid.Column="1" Grid.Row="3" Height="23" HorizontalAlignment="Left" Margin="6" Name="CmbBStaff" VerticalAlignment="Top" Width="170" ItemsSource="{Binding}"/>
(我是wpf的新手)
谢谢
推荐答案
我相信以下链接可能对您有用:
I believe the following link may be useful to you:
http://stackoverflow.com/questions/561166/binding-wpf-combobox-to-custom-list
这篇关于绑定到ComboBox SelectedValue和ItemsSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!