一個WPF ComboBox項誰能幫我用值屬性查找ComboBox項。組合框綁定到數據集。 這是我的代碼。查找使用的SelectedValue從綁定的組合框
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>
根據員工選擇,我想顯示他的名稱。在數據庫中,我只有指定代碼(Desig_Code),它已映射到SelectedValuePath中。
我該如何做到這一點?
我有cbxDesignation.SelectedValue
如下
cbxDesignation.SelectedValue = (dsMaster.Tables[0].Rows[0]
["Desig_Code"].ToString() != "") ? dsMaster.Tables[0].Rows[0]
["Desig_Code"].ToString() : "0";
請幫助任何人.....
謝謝。
任何人在那裏幫助我嗎? – 2013-05-02 15:43:30
HELLO ANYBODY那裏幫助MEEEEEE ... – 2013-05-06 17:08:35
你好..................我想用基於從所選擇的員工ID的所有細節,以填充員工定義格式格。 emp指定組合框的Desig_descr爲Displaymemberpath&Desg_Code作爲selectedvaluepath。現在基於emp ID,我從DB獲得了Desig_Code,並且想要在組合框中拾取並顯示正確的Desig_Descr。 – 2013-05-06 17:47:03