A ListView control allows to display a list of items. ListView is very similar to windows explorer. In ListView you can list the items in list view, icon view, detail view.
Drag and drop ListView control from toolbox on the WindowForm.
using System;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class frmListView : Form
{
public frmListView()
{
InitializeComponent();
}
private void frmListView_Load(object sender, EventArgs e)
{
//specify which view should display of listview Item
listView1.View = View.Details;
// add columns in ListView
listView1.Columns.Add("Emp Id", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Emp Name", 100, HorizontalAlignment.Left);
// add Items in ListView
listView1.Items.Add("UMS101").SubItems.Add("Yash");
listView1.Items.Add("UMS102").SubItems.Add("Raj");
}
}
}
You can change its view in details,LargeIcon,SmallIcon,Tile,List through its view property.
When you set listView1.View = View.Tile; then listview data will show in Tile View.
View: Defines how items are displayed in the control.
CheckBoxes: Indicates whether a check box appears next to each item in the control.
Example:
private void frmListView_Load(object sender, EventArgs e)
{
// appears checkBox next to each Item
listView1.CheckBoxes = true;
}
Output
CheckBox will appear when the application run.
TileSize: Defines the size of the tiles shown in tile view.
BackColor: Set BackColor of ListView.
Example:
private void frmListView_Load(object sender, EventArgs e)
{
// Change BackColor Of ListView
listView1.BackColor = Color.CadetBlue;
}