Avatar of vcurtis
vcurtis
 asked on

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;
                  };
            }

      }
}
.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
vcurtis

8/22/2022 - Mon
Ess Kay

here is a basic way to populate a listbox



List<string> MyList = new List<string>();
MyList.Add("HELLO");
MyList.Add("WORLD");
Ess Kay

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);      
       }
}
SOLUTION
Manoj Patil

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
vcurtis

ASKER
The listbox does not have an "add" method in its intellisence
Your help has saved me hundreds of hours of internet surfing.
fblack61
Manoj Patil

Try this method
Listbox.items.add
vcurtis

ASKER
I tried it both ways and got errors
listbox.docx
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
vcurtis

ASKER
Thanks everyone, I was able to devise a solution with the  tips  you provided
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.