A ListView control allows displaying a list of items. ListView is very similar to windows explorer. In
ListView you can list the items in the ListView, icon view, detail view.
How to use ListView Control
Drag and drop ListView control from the toolbox on the WindowForm.
Code:
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");
}
}
}
Run the project
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.
ListView Properties:
View: Defines how items are displayed in the control.
CheckBoxes: Indicates whether a checkbox 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
The CheckBox will appear when the application run.
Tile size: Defines the size of the tiles shown in the tile view.
BackColor: Set BackColor of ListView.
Example:
private void frmListView_Load(object sender, EventArgs e)
{
// Change BackColor Of ListView
listView1.BackColor = Color.CadetBlue;
}
Anonymous User
05-Mar-2019Nice Post.
Samuel Fernandes
31-Jul-2017Your words increase my knowledge for sure. Thanks