使用linq将集合数据显示为字符串值 [英] display collection data as string values using linq

查看:67
本文介绍了使用linq将集合数据显示为字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个编码对我来说似乎不错,但出于某种原因,当在组合框中选择一个项目时,它会在列表视图中列出,而不会在项目内显示数据。当我在我的xaml中删除listview.view时,该项显示(collection)。



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)".

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"/>

推荐答案

这可能是一个拳击问题 - 尝试让你的PIDData成为一个类而不是一个结构。



它仍然超出了建议的结构指南:Microsoft推荐一个maximu m是16个字节,你的x64机器上将是64个字节。
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.


这篇关于使用linq将集合数据显示为字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆