Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | Videos | Photos | Blogs | Beginners | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
Mindcracker MVP Summit 2012
Search :       Advanced Search »
Home » Windows Controls » Multi Column ListView Control in VB.NET

Multi Column ListView Control in VB.NET

There are many questions about adding multiple columns to a ListView control. Some times its hard for beginners to find even small clues like ListView multi column won't work until you set its View property as Details.

Author Rank :
Page Views : 232555
Downloads : 1878
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
MultiListViewSampMCB.zip
 
 
Mindcracker MVP Summit 2012
Become a Sponsor
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


There are many questions about adding multiple columns to a ListView control. Some times its hard for beginners to find even small clues like ListView multi column won't work until you set its View property as Details.

Any way, this small article explains how to create a multi column list view control and add data to it.

Creating Project

First create a Windows Application project in Visual Studio .NET and drop a ListView control from toolbox to the form. After that first thing you need to do is to set View property of list view control to Details. See figure 1.


MultiColListViewMCB1.gif

Figure 1. Setting ListView Control's View Property to Details.

The View property can have any of following members of View enum.

Member Description
Details Each item appears on a separate line with further information about each item arranged in columns. The left most column contains a small icon and label, and subsequent columns contain sub items as specified by the application. A column displays a header which can display a caption for the column. The user can resize each column at runtime.
LargeIcon Each item appears as a full-sized icon with a label below it.
List Each item appears as a small icon with a label to its right. Items are arranged in columns with no column headers.
SmallIcon Each item appears as a small icon with a label to its right.

You can also set this property programmatically by using the following code:

ListView1.View = System.Windows.Forms.View.Details

Adding Multiple Columns

Now I add five columns to the control. You can add column headers to the control using its Columns.Add method. The Columns.Add method takes column header name, its width, and alignment.

In our sample, I write code at Form_Load method to do so. See Listing 1.
Private
Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Adding ListView Columns
ListView1.Columns.Add("Emp Name", 100, HorizontalAlignment.Left)
ListView1.Columns.Add("Emp Address", 150, HorizontalAlignment.Left)
ListView1.Columns.Add("Title", 60, HorizontalAlignment.Left)
ListView1.Columns.Add("Salary", 50, HorizontalAlignment.Left)ListView1.Columns.Add("Department", 60, HorizontalAlignment.Left)
End Sub

Listing 1. Adding Column Headers of a ListView Control

After adding this code, the output of program looks like Figure 2.

MultiColListViewMCB2.gif

Figure 2. Multiple Column Headers

Adding Records

ListView.Item.Add method adds records to a list view control. The Add method takes ListViewItem type value. For multi column list view control, we create a ListViewItem with an array of 5 string items. The following code adds a record to the list view control.


Dim
str(5) As String
Dim
itm As ListViewItem
str(0) = "Rob Machy"
str(1) = "100 North Ave"
str(2) = "Business Manager"
str(3) = "89,000"
str(4) = "Development"
itm =
New ListViewItem(str)
ListView1.Items.Add(itm)

After setting more properties of the list view control and adding more records, our list program looks like Figure 3.

MultiColListViewMCB3.gif

Figure 3. Multi Column ListView Control 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Mahesh Chand
Mahesh is the founder of C# Corner and Mindcracker Network, an author of several .NET programming books and a Microsoft MVP for 6 consecutive years. In his day to day work, Mahesh is a Senior Software Consultant with over 14 years of IT industry experience building systems for Financial and Banking, Engineering & Architectural, Imaging, Construction, Biological & Pharmaceuticals, Healthcare and Education industries. His expertise is Windows Forms, ASP.NET, Silverlight, WPF, WCF, Visual Studio 2010, SQL Server, and Oracle.  If you are looking for a Sharepoint, Windows Forms, ASP.NET, WPF, Silverlight, C#, VB.NET, Oracle, and SQL Server Consultant in Philadelphia area or remote location, drop me a line at MAHESH [AT] C-SHARPCORNER [DOT] COM.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
 Comments
C# by jyothi On June 12, 2007
how to change the color for coloumn headers in listview
Reply | Email | Modify 
Thankyou very much by Grant On September 3, 2009
Thanks for this. Really good stuff, straight forward and to the point.

Just what I needed.
Reply | Email | Modify 
Multi listview by Manikandan On March 29, 2010
Multi list view coding is very use ful to me. i want to crystal report process by using MySql Back end of my project.
Reply | Email | Modify 
Great Explanataion! by Val On May 23, 2010
  Thanks a lot, the exact thing needed!!
Reply | Email | Modify 
Re: Great Explanataion! by Mahesh On May 23, 2010
I am glad Val that you found it useful.
Reply | Email | Modify 
remove item by pras On May 30, 2010
how to remove item, and move data to textbox
Reply | Email | Modify 
list view by reena On June 2, 2010
How to add dat to multiple columns at runtime i.e please elaboratre the coding for fig.3
Reply | Email | Modify 
Listview Control by Bradley On August 3, 2010
That was a great tip thanks
is there a way that you can edit that same item rather than adding a new item each time
so if the information changes in item 1 you can update the information with out adding the item again

Many thanks

BJseal91
Reply | Email | Modify 
invoice by Kassem On November 26, 2010
hello i want to make a program that contains a place for enterning data of an invoice for supermarket what to use ? datagrid view?? or exel?? and how?
Reply | Email | Modify 
Re: invoice by Mahesh On December 1, 2010
Search this site or C# Corner for Invoice. There are some sample articles/code on this topic.
Reply | Email | Modify 
Please expand on Figure 3 by Myles On November 26, 2010
This article was useful until figure 3. Could you please explain on how you populated the data for figure 3. Thanks
Reply | Email | Modify 
Re: Please expand on Figure 3 by Mahesh On December 1, 2010
If you are using Visual Studio 2008 or 2010, there is a ListView control. You can use that control which provides better features. This article was written long ago.
Reply | Email | Modify 
Re: Re: Please expand on Figure 3 by kenmeidearu On June 4, 2011
how to implementation using c# please help me
Reply | Email | Modify 
ListView by durga On December 31, 2010
Hi, This Articles is more helpful for me and good explanation. i have one question in this concept 1. I stored all items in the Listview. but I want to know How to store these item values in the DataBase in the Same ColumnNames order. Give Solution for this question.
Reply | Email | Modify 
ListView by bala On February 25, 2011
very best coding sir thank you so much
Reply | Email | Modify 
Adjusting the Column Header of the listview Control by Stephen On March 14, 2011
Please I want to adjust the column header height of a listview controll. how can i go about this..
Reply | Email | Modify 
How to save? by Juha On April 11, 2011
Whats the code if user adds records and want to save it?
Reply | Email | Modify 
Prevent user from entering duplicate items by Samirah On July 16, 2011
Im a learner and am kind of stuck on this one. Whatif i want to prevent a user from entering duplicate items in the listview and the application show display a messagebox informing the dup.
Reply | Email | Modify 
Listview Column by Alessandro On January 20, 2012
How can i set only one column in a multi-column listview as read-only?
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.