ListView
Written by: maffelu , 2009-05-16 16:11:02
listView1.View = View.Details;
listView1.CheckBoxes = true;
listView1.FullRowSelect = true;
listView1.GridLines = false;
listView1.Width = 260;
listView1.Columns.Add("Name", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Age", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Idiot", 60, HorizontalAlignment.Left);
ListViewItem item1 = new ListViewItem("Rod");
item1.Checked = false;
item1.SubItems.Add("8");
item1.SubItems.Add("Yes");
listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });
using System;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace listview
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//==============SETUP================================================
//So that we can see the details :)
listView1.View = View.Details;
//Implement checkboxes
listView1.CheckBoxes = true;
//So that the entire item (and subitem) is selected by the user
listView1.FullRowSelect = true;
//Hide gridlines
listView1.GridLines = false;
//Since we don't want to have a listview with a scrollbar, we set
//the width at startup and apply this to the columns
listView1.Width = 260;
//100 + 100 + 60 = 260, the total width of the listview
listView1.Columns.Add("Name", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Age", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Idiot", 60, HorizontalAlignment.Left);
//===============LOADING=============================================
ListViewItem item1 = new ListViewItem("Rod");
item1.Checked = false;
item1.SubItems.Add("8");
item1.SubItems.Add("Yes");
ListViewItem item2 = new ListViewItem("Todd");
item2.Checked = false;
item2.SubItems.Add("10");
item2.SubItems.Add("Yes");
ListViewItem item3 = new ListViewItem("Lisa");
item3.Checked = true;
item3.SubItems.Add("10");
item3.SubItems.Add("No");
listView1.Items.AddRange(new ListViewItem[] { item1, item2, item3 });
}
}
}
There are no comments on this article.
If you have any question or just want to leave a message, just fill out the form below!
Your e-mail will not be visible in your post, it is for validation reasons only
Maffelu
Creator and admin of MorkaLork.com.
Started programming in HTML back when frames and tables was the way to design a page, moved on to Pascal/Delphi, PHP, javascript/jQuery, VB.NET/C#, Java and C++.
Currently studies .NET (in general) focusing on ASP.NET.