Adding Items to ListView Control

by Shabbir on May 15, 2008

in C#

Adding items to list view is more difficult than adding items to list box. And in general the ListView control is more complex than the ListBox, and that makes it more difficult to work with.

So, in a C# project, create this form

ListView form

The controls have the default names in Visual Studio 2008.

Than click on the little button in the top right corner of the ListView

ListView properties

Than from the options of the View dropdown menu select Details. Now, click on the Edit Columns link and create two columns

You can optimize the column width.

Now, in the button1 click event write this code

  1. string[]str={textBox1.Text, textBox2.Text};
  2. ListViewItem lvItem = new ListViewItem(str);
  3. listView1.Items.Add(lvItem);

We are creating a string that contains the text written in the text boxes, and it will be inserted in the list view control. Then we create a ListViewItem object and assign the values to it, and in the end we insert the ListViewItem object in the listView1 control.

Run the application and write something ni the text boxes, then click the button. The values will be entered in the list view control.

Download the project

Sharing is Caring...

Leave a Comment

Previous post:

Next post:

    About the Author

  • author photo

    My Name is Shabbir Bhimani and I am developer by profession in the field of applications, web and database. Currently doing full time online marketing and like to share my experiences on how you can make money online @ CodeItWell.com. Read more ...


    See how you can get in touch with me.