0
XAML代碼:組合框表示System.Data.DataRowView在WPF
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
<xctk:CheckComboBox x:Name="Cb_Blowshell" HorizontalAlignment="Left" Margin="195,9,0,0" Grid.Row="2" VerticalAlignment="Top" Width="267" DisplayMemberPath="prod_name" ValueMemberPath="Id" ItemsSource="{Binding}"/>
C#代碼
DataTable dt = new DataTable("blow_shell");
String Qry = "select Id,prod_name from blow_shell where weight=" + Txt.Text.Trim().ToString() + "";
SqlHelper.Fill_dt(dt, Qry);
Cb_Blowshell.ItemsSource= dt.DefaultView;
及其簡要代碼以數據表中的數據綁定到組合框;但我的顯示成員顯示System.Data.DataRowView
。
請幫我解決。
Cb_Blowshell.ItemsSource= dt.DefaultView;
我猜你想爲每個項目在CheckComboBox
內容,以顯示你的數據庫表的prod_name
列:
嘿嘗試這種方法,工作正常,但我希望既顯示成員和值成員。 –
你想要展示什麼?在你的select語句中只有「Id」和「prod_name」。您可以爲這兩個字段創建一個類,創建這些對象的列表並將它們綁定爲項目源。在這種情況下,您必須設置「DisplayMemberPath」。有關詳細信息,請參閱此處:http://stackoverflow.com/a/4902454/4424024 – Martin