组合框,显示wpf中的System.Data.DataRowView
本文关键字:System Data DataRowView 中的 wpf 显示 组合 | 更新日期: 2023-09-27 18:14:47
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;
它将数据表数据绑定到组合框的简短代码;但是我得到的显示成员显示CCD_ 1。
请帮我解决。
您不能使用以下代码行绑定数据:
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();
。