Reputation:
I Have three objects in a combo box when they are selected the items are listed in the List View. The items are added but there is no text inside the rows like the names of the objects. and when I remove the ListView.View from my Xaml the items displays "(Collection)"
//ComboBox Binding
public void BindComboBox()
{
using (DataClassesDataContext DC = new DataClassesDataContext())
{
cbItem.Items.Clear();
foreach (tblProduct R in DC.tblProducts)
cbItem.Items.Add(R);
cbItem.DisplayMemberPath = "ProductName";
}
//Combobox selectionChanged
List<PIDData> items = new List<PIDData> { };
IEnumerable<PIDData> query = items.Where(item => item.PName != null);
lvDataBinding.Items.Add(items);
txt1.Text = query.ToString();
//Xaml
<ListView Margin="338,20,1,16" Name="lvDataBinding">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding PName}">
<GridViewColumnHeader Tag="Product Name" Width="100">Product Name</GridViewColumnHeader>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ComboBox x:Name="cbItem" HorizontalAlignment="Left" Margin="13,315,0,0" VerticalAlignment="Top" Width="321" SelectionChanged="cbItem_SelectionChanged"/>
Upvotes: 0
Views: 102
Reputation: 6267
Well what you are doing is that you are adding the LINQ Query result as "one object" to your list view. So the list view is not dealing with each piddata but with one "IEnumable".
So either you are adding them one by one or you change to assignment of ItemsSource.
Upvotes: 1