Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This coding seems fine to me but for some reason when an item is selected in the combobox it gets listed in the listview without showing data inside of the item. and when I remove the listview.view in my xaml the item shows "(collection)".

C#
public struct PIDData
        {
            public long PIdentity { get; set; }
            public string PName { get; set; }
            public string PPrice { get; set; }
            public string PSerial { get; set; }
            public string PDescription { get; set; }
            public string PType { get; set; }
            public string PPosition { get; set; }
            public Binary PImage { get; set; }
        }


       //Binding combobox
             using (DataClassesDataContext DC = new DataClassesDataContext())
           {
               cbItem.Items.Clear();
               foreach (tblProduct R in DC.tblProducts)
               cbItem.Items.Add(R);
               cbItem.DisplayMemberPath = "ProductName";
           }

        //Combobox Selection changed
           List<string> items = new List<string> { cbItem.SelectedItem.ToString() };

            IEnumerable<string> query = items.Where(item => item.ToString() != null);
            lvDataBinding.Items.Add(items);
            

            txt1.Text = items.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"/>
Posted
Updated 14-Apr-15 22:14pm
v2

1 solution

It's probably a boxing problem - try making your PIDData a class instead of a struct.

It's way outside the recommended guidelines for a struct anyway: Microsoft recommend a maximum of 16 bytes, and yours is going to be 64 bytes on a x64 machine.
 
Share this answer
 
Comments
RenaldoGG 15-Apr-15 5:39am    
it also doesn't work but is worth knowing thanks, the items are added in the listview but doesn't show any text.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900