ListView Control in C#.Net

来源:互联网 发布:linux ed2k 下载工具 编辑:程序博客网 时间:2024/06/05 08:56

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.

How to use ListView Control

Drag and drop ListView control from 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 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.

ListView Control in C#.Net

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;

 }

ListView Control in C#.Net