Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Populating a Listbox in c#

Posted on 2012-12-26
9
Medium Priority
?
265 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 666 total points
ID: 38721910
Just replace this to your last line of code
ListBox1.Add(String.IsnullorEmpty(cust.toString()))
0
Implementing Azure Infrastructure Exam 70-533

This course is designed to familiarize and instruct students in the content that is covered by Microsoft Exam 70-533, Implementing Microsoft Azure Solutions. It focuses on all the November 2016 objective domain topics.

 

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 334 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 666 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

722 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