[英]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.