using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace add_item_to_listview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void add_Items_Listview_Click(object sender, EventArgs e)
{
string[] row1 = { "item1", "item2", "item3" };
string[] row2 = { "item11", "item21", "item31" };
var listViewItem1 = new ListViewItem(row1); ;
var listViewItem2 = new ListViewItem(row2);
listView1.Items.Add(listViewItem1);
listView1.Items.Add(listViewItem2);
}
private void add_Items_Listview1_Click(object sender, EventArgs e)
{
Pet pet = new Pet() { Name = "cat", Type = "Persian", Age = "2" };
ListViewItem lvi = new ListViewItem();
lvi.Text = pet.Name;
lvi.SubItems.Add(pet.Type);
lvi.SubItems.Add(pet.Age);
listView1.Items.Add(lvi);
}
class Pet
{
public string Name { get; set; }
public string Type { get; set; }
public string Age { get; set; }
}
}
}
Download the project of Visual Studio 2013 in DropBox Download