Solved

ListView

Posted on 2009-07-10
3
304 Views
Last Modified: 2012-05-07
I have added a ListView to my form.

I have a class Called Contact with name, lastname and phone nr.
How do I add all this to my listview?
All my contacts is in a List<Contact>

And....finally is it possible to add a dropdownlist in a listview? For example if my phone nr will be added in alist so you can have more than one phone nr?
0
Comment
Question by:Mickeys
[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
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
angus_young_acdc earned 500 total points
ID: 24824426
The follow snippet will add each of your contacts from the list to your ListView.  As for a dropdownlist, you would need to google for a custom listview control.
foreach (Contact contact in contacts)
            {
                ListViewItem subItem = listView1.Items.Add(contact.Name);
                subItem.SubItems.Add(contact.LastName);
                subItem.SubItems.Add(contact.PhoneNr);
            }

Open in new window

0
 
LVL 15

Expert Comment

by:angus_young_acdc
ID: 24824444
Oh should add to that, be sure have created the columns in your list view.
0
 

Author Comment

by:Mickeys
ID: 24829257
Right now they appear after each other like this

Mike Andersson        Peter Carlsson   .......

I want them to be each on one row like:
Mike Andersson
Peter Carlsson
......

and also....how do I add column name?
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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