In this article I will explain how to binding array list to C# listview.
First you need to create New Project and Name of project is DisplayArrayListToListview, and Add the Command button and ListView control and copy this code and paste.
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Collections;
namespaceDisplayArrayListToListview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private voidCmdArrList_Click(object sender, EventArgs e)
{
//Multi Dimensional Array
string[,] ArrayList ={
{“101”,“John”,“5000”},
{“102”,“Ajay”,“8000”},
{“103”,“Fleming”,“10000”}
};
listView1.Items.Clear();
for(inti=0;i<3;i++)
{
ListViewItem lv = newListViewItem();
lv.Text = ArrayList[i, 0];
lv.SubItems.Add(ArrayList[i, 1]);
lv.SubItems.Add(ArrayList[i, 2]);
listView1.Items.Add(lv);
}
}
private voidForm1_Load(object sender, EventArgs e)
{
listView1.GridLines = true;
listView1.View = View.Details;
//Add Column Header
listView1.Columns.Add(“ID”, 50);
listView1.Columns.Add(“Name”, 50);
listView1.Columns.Add(“Salary”, 50);
}
}
}
(h)