【问题标题】:receiving an array from a WCF service and display it into a listbox从 WCF 服务接收数组并将其显示到列表框中
【发布时间】:2012-03-30 11:29:03
【问题描述】:

我正在尝试使用来自 wcf 服务的对象的条目来填充列表框 我基本上发送一个组请求,然后我收到一组与请求匹配的组。 但是我设法只显示对象的名称而不是其内容。

有什么想法吗?我可能错过了明显的,但无法真正发现它。

        int i = 1;
        GroupServiceClient client = new GroupServiceClient("WSHttpBinding_IGroupService");
        www.test.co.uk.User.user User = new www.test.co.uk.User.user();
        www.test.co.uk.programme.programme Group = new www.test.co.uk.programme.programme();
        www.test.co.uk.programme.programme[] Groups = new www.test.co.uk.programme.programme[i];

        DateTime time = DateTime.Now;
        values.Clear();
        client.Open();

        Group.number = Convert.ToString(textBox1.Text);
        client.GetGroups(ref time, Group);


        GroupArrayMessage toReturn = new GroupArrayMessage();
        toReturn.groups = Groups;


        listBox1.ItemsSource = Groups.ToString(); ;

【问题讨论】:

    标签: c# wpf wcf


    【解决方案1】:
    listBox1.ItemsSource = Groups;       // no .ToString()
    listBox1.DisplayMemberPath = "Name"; // should be a Group property
    

    【讨论】:

    • 谢谢,但我在 listBox1 中没有 DisplayMember 功能
    • 再次感谢仍然没有,如果我反转回 toString 它会返回 www.test.co.uk.programme.programme[] 每行一个字符。
    • 你能描述“什么都没有”吗?也许您需要 ToList() ,但肯定不需要 ToString()
    • 列表框保持空白,而如果我尝试使用 wcftestclient 我会得到组列表,所以我知道后端很好。
    • 使用调试器和/或输出窗口。
    【解决方案2】:

    首先 您不能使用 Group.ToString() 因为任何 ItemControl 的 ItemSource 属性只接受列表类型的对象

    所以 使用

    listBox1.ItemSource = Groups;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-18
      • 2020-02-27
      • 2013-03-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-08
      相关资源
      最近更新 更多