Solved

Populating a Listbox in c#

Posted on 2012-12-26
9
264 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 

Author Comment

by:vcurtis
ID: 38721982
The listbox does not have an "add" method in its intellisence
0
 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

628 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