Solved

ListView

Posted on 2009-07-10
3
299 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
  • 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

17 Experts available now in Live!

Get 1:1 Help Now