2

I am trying to pupulate a listbox with entries of an object which comes from a wcf service I basically send a request for a group and I receive an array of groups that match the request. however I managed just to display the name of the object rather thna its content.

any idea? I have might missed the obvious but cannot really spot it.

        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(); ;

2 Answers 2

4
listBox1.ItemsSource = Groups;       // no .ToString()
listBox1.DisplayMemberPath = "Name"; // should be a Group property
7
  • 1
    Thanks but I don't have the function DisplayMember in the listBox1 Mar 30, 2012 at 11:49
  • Thanks again still nothing, if I reverse back toString it returns back www.test.co.uk.programme.programme[] a character per each line. Mar 30, 2012 at 12:24
  • Can you describe "nothing" ? Maybe you need a ToList() , but certainly not a ToString() Mar 30, 2012 at 13:13
  • 1
    The listbox remains blank, whereas if I try with wcftestclient I get the list of groups, so I know that the back end is fine. Mar 30, 2012 at 13:27
  • Use the Debugger and/or Output Window. Mar 30, 2012 at 14:34
1

First You can't use Group.ToString() because ItemSource Property of any ItemControl accept only list kind of object

So Use

listBox1.ItemSource = Groups;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.