【发布时间】:2013-05-02 15:02:07
【问题描述】:
任何人都可以帮助我使用 value 属性找到 Combobox 项。组合框绑定到数据集。 这是我的代码。
XAML 代码
ComboBox Grid.Column="0" Grid.Row="3" Height="23" HorizontalAlignment="Left"
Margin="12,23,0,0" Name="cbxDesignation" VerticalAlignment="Top" Width="120"
ItemsSource="{Binding}" SelectedValuePath="Desig_Code" SelectedItem="Desig_Name"
C# 代码。
//Populate Designation
<i> strSQL = "SELECT Desig_Code, Desig_Name FROM Desig_Master";
dsCommon = CDTier.ReturnDataSet(strSQL);
cbxDesignation.DataContext = dsCommon.Tables[0].DefaultView;
cbxDesignation.DisplayMemberPath = dsCommon.Tables[0].Columns["Desig_Name"].ToString();
cbxDesignation.SelectedValuePath = dsCommon.Tables[0].Columns["Desig_Code"].ToString();
if (dsCommon.Tables[0].Rows.Count > 0)
cbxDesignation.SelectedIndex = 0;
dsCommon.Dispose();
</i>
根据员工选择,我想显示他的名称。在数据库中,我只有在 SelectedValuePath 中映射的指定代码 (Desig_Code)。
我怎样才能做到这一点?
我有如下cbxDesignation.SelectedValue
cbxDesignation.SelectedValue = (dsMaster.Tables[0].Rows[0]
["Desig_Code"].ToString() != "") ? dsMaster.Tables[0].Rows[0]
["Desig_Code"].ToString() : "0";
请帮助任何人.....
谢谢。
【问题讨论】:
-
有人帮我吗?
-
你好,任何人都可以帮助 MEEEEEE...
-
您好..................我想根据从网格中选择的员工 ID 使用所有详细信息填充员工定义表单。 emp 指定组合框将 Desig_descr 作为 Displaymemberpath,将 Desg_Code 作为 selectedvaluepath。现在基于 emp ID,我从 DB 获得了 Desig_Code,我想在组合框中获取并显示正确的 Desig_Descr。
标签: wpf data-binding combobox selecteditem selectedvalue