Solved

Populating a Listbox in c#

Posted on 2012-12-26
9
256 Views
Last Modified: 2012-12-31
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;
                  };
            }

      }
}
0
Comment
Question by:vcurtis
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 38721749
here is a basic way to populate a listbox



List<string> MyList = new List<string>();
MyList.Add("HELLO");
MyList.Add("WORLD");
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 38721756
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
 
LVL 19

Assisted Solution

by:Manoj Patil
Manoj Patil earned 333 total points
ID: 38721910
Just replace this to your last line of code
ListBox1.Add(String.IsnullorEmpty(cust.toString()))
0
 

Author Comment

by:vcurtis
ID: 38721982
The listbox does not have an "add" method in its intellisence
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 19

Expert Comment

by:Manoj Patil
ID: 38721994
Try this method
Listbox.items.add
0
 

Author Comment

by:vcurtis
ID: 38722297
I tried it both ways and got errors
listbox.docx
0
 
LVL 3

Assisted Solution

by:brezniczky
brezniczky earned 167 total points
ID: 38723041
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
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 333 total points
ID: 38723508
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
 

Author Comment

by:vcurtis
ID: 38733684
Thanks everyone, I was able to devise a solution with the  tips  you provided
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now