[英]combobox showing System.Data.DataRowView in wpf
XAML代碼:
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;
我猜你想要顯示的prod_name
為每個項目中的內容數據庫表的列CheckComboBox
。
試試看(在“ Fill_dt”方法調用后插入):
List<string> names = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
String prodName = Convert.ToString(dt.Rows[i]["prod_name"]);
names.Add(prodName );
}
Cb_Blowshell.ItemsSource = names;
順便說一句:您的輸出“ System.Data.DataRowView
”是您嘗試綁定到源類型的典型示例,在這種情況下, DataRowView
不適合目標控件(在您的情況下: CheckComboBox
) 。 在這種情況下,您將看到綁定源對象的ToString
方法的輸出。 因此,在這里您可以看到執行此操作的Object
基類的“ ToString”方法的輸出: this.GetType().ToString();
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.