Thursday, November 22, 2012

Binding data to a ListView with Multiple Columns in C# Windows Form

A ListBox control in a C# windows forms, can display only one column of data, but there are instances when we want to display multiple columns of data. One option is to use the DataGrid control, but we can also use the ListView control to display multiple column data.

ListView can be used to display static information, which the user will not be changing, in this post we shall see on how to use the ListView control to display multiple columns of data in a C# Windows Form. We shall bind the data from the list view from the code behind file.

1. Create a new / open an existing C# Windows application
2. Open and existing / Add a new Windows Form to the Project
3. Drag
a ListView control into the form.
4. Open the Properties window of the ListView.
5. Open the Columns (Collection) Property of the
ListView and add the Columns Required.
6. Now switch to the code behind and add the following code to populate the ListView.

            ListViewItem listViewItem;
            listViewItem = new ListViewItem("<= 18.5");
            listViewItem = new ListViewItem("18.5 to 25");
            listViewItem.SubItems.Add("Normal Weight");
            listViewItem = new ListViewItem("25.1 to 30");
            listViewItem = new ListViewItem("> 30");

7. The Final ListView looks as follows.

Search Flipkart Products:

1 comment:

samuel fernandes said...


This is a nice article. Thank for sharing your knowledge. There are some other links related to "Binding XML Data to

ListView Control in C#". I hope this is a very useful for developers.