1

xaml code:

 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# code

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;

Its brief code to bind datatable data to combobox; but my resulted display member show System.Data.DataRowView.

Please help me to solve.

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
Rashmi S
  • 267
  • 1
  • 7
  • 20

1 Answers1

0

You can not bind the data using this line of code:

Cb_Blowshell.ItemsSource= dt.DefaultView;


I guess you want to display the prod_name column of your database table as the content of each item in the CheckComboBox.

Try this (insert it after the "Fill_dt" method call):

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;


By the way: Your output "System.Data.DataRowView" is a typical example of when you try to bind to a source type in this case DataRowView which does not fit to the target control (in your case: an item of the CheckComboBox). In this case you will see the output of the ToString method of the bound source object. So here you see the output of the "ToString" method of the Object base class which does this: this.GetType().ToString();.

Martin
  • 5,165
  • 1
  • 37
  • 50
  • Hey try with this method,works fine but i want both display member and value member. – Rashmi S Sep 29 '15 at 05:24
  • What exactly do you want to display? There is only "Id" and "prod_name" in your select statement. You could create a class for these two fields, create a list of those objects and bind them as items source. In this case you have to set the `DisplayMemberPath`. See here for more info: http://stackoverflow.com/a/4902454/4424024 – Martin Sep 29 '15 at 06:19