The ListView control is an ItemsControl that is derived from ListBox.
![C# listview](https://i-blog.csdnimg.cn/blog_migrate/1882ef345a2e17e871c96b29126e6c87.png)
Add Columns in ListView
You can add columns in Listview by using Columns.Add() method. This method takes two arguments, first one is the Column heading and second one the column width.
listView1.Columns.Add("ProductName", 100);
In the above code, "ProductName" is column heading and 100 is column width.
Add Item in Listview
You can add items in listbox using ListViewItem which represents an item in a ListView control.
string[] arr = new string[4]; ListViewItem itm;//add items to ListView arr[0] = "product_1"; arr[1] = "100"; arr[2] = "10"; itm = new ListViewItem(arr); listView1.Items.Add(itm);
Get selected item from ListView
productName = listView1.SelectedItems[0].SubItems[0].Text;
Above code will return the itme from first column of first row.
Sorting Listview Items
If the Sorted property of Listview is set to true, then the ListView items are sorted. The following code sorts the ListView items:
ListView1.Sorted = true;
Add Checkbox in Listview
You can add checkbox in Listview columns.
myListView.CheckBoxes = true;myListView.Columns.Add(text, width, alignment);