Populating a Listbox in c#

I am new to .net. I am trying to populate a listbox with the following code. what am I doing wrong? The compiler complaigns about the last line saying "cannot convert a non deligate type"

      private void popList()
            {
                  var context = new AWDEntities();
                  {
                        var query = from c in context.COMMITTEES
                                          where c.COMMITTEE_ID == 5
                                          select new { c.COMMITTEE_HOUSE, c.COMMITTEE_MEMBERSHIP, c.COMMITTEE_HEARING_AGENDAS };
                        var cust = query.First();
                        ListBox1.Text = cust.ToString;
                  };
            }

      }
}
vcurtisAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Manoj PatilConnect With a Mentor Sr. Software EngineerCommented:
Is your variable var cust  returns multiple data.
If yes then try with this

foreach (string newCust in cust)
{
    Console.WriteLine(newCust);
}

Open in new window

0
 
Ess KayEntrapenuerCommented:
here is a basic way to populate a listbox



List<string> MyList = new List<string>();
MyList.Add("HELLO");
MyList.Add("WORLD");
0
 
Ess KayEntrapenuerCommented:
try this



   private void popList()
{
                  var context = new AWDEntities();
     {
                        var query = from c in context.COMMITTEES
                                          where c.COMMITTEE_ID == 5
                                          select new { c.COMMITTEE_HOUSE, c.COMMITTEE_MEMBERSHIP, c.COMMITTEE_HEARING_AGENDAS };
                        var cust = query.First();
                        ListBox1.Add(cust.ToString);      
       }
}
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
Manoj PatilConnect With a Mentor Sr. Software EngineerCommented:
Just replace this to your last line of code
ListBox1.Add(String.IsnullorEmpty(cust.toString()))
0
 
vcurtisAuthor Commented:
The listbox does not have an "add" method in its intellisence
0
 
Manoj PatilSr. Software EngineerCommented:
Try this method
Listbox.items.add
0
 
vcurtisAuthor Commented:
I tried it both ways and got errors
listbox.docx
0
 
brezniczkyConnect With a Mentor Commented:
I guess based on the error message you received, the problem is a few missing chars as below:

ListBox1.Text = cust.ToString(); // mind the trailing parentheses

as ToString is treated as a method reference otherwise rather than an actual method call.
0
 
vcurtisAuthor Commented:
Thanks everyone, I was able to devise a solution with the  tips  you provided
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.