articles

Home / DeveloperSection / Articles / ListView Control in C#.Net

ListView Control in C#.Net

ListView Control in C#.Net

Anonymous User 26612 24-Jan-2011

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.

ListView Control in C#.Net

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

ListView Control in C#.Net

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 Control in C#.Net

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.

ListView Control in C#.Net

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;
 }

ListView Control in C#.Net


c# c# 
Updated 29-Mar-2020
I am a content writter !

Leave Comment

Comments

Liked By