Friday 14 November 2008

Listviews, Listviews, Listviews.... in C#.NET

If you want to create something like this:


you will need to talk with the ListView control. This control combines the functionality of a list with all the fancy features of the lastest .NET properties.

This is the code you need for a control called "LSTResults":


this.LSTResults.Items.Clear();

LSTResults.Columns.Add("Name", 100,HorizontalAlignment.Left);
LSTResults.Columns.Add("Size", 70, HorizontalAlignment.Left);
LSTResults.Columns.Add("Date Modified", 70, HorizontalAlignment.Left);
LSTResults.Columns.Add("Location", 70, HorizontalAlignment.Left);


ListViewItem _lvItem1 = new ListViewItem("IMAGE_063.jpg", 1);
_lvItem1.SubItems.Add("227120"+ " KB");
_lvItem1.SubItems.Add("12/10/2008");
_lvItem1.SubItems.Add("sdfsdf/IMG");
this.LSTResults.Items.Add(_lvItem1);

ListViewItem _lvItem2 = new ListViewItem("Contact-new1.jpg", 2);
_lvItem2.SubItems.Add("58383"+ " KB");
_lvItem2.SubItems.Add("12/10/2008");
_lvItem2.SubItems.Add("Personal/IMG");
this.LSTResults.Items.Add(_lvItem2);

ListViewItem _lvItem3 = new ListViewItem("PWS-Explorer", 2);
_lvItem3.SubItems.Add("2659"+ " KB");
_lvItem3.SubItems.Add("12/10/2008");
_lvItem3.SubItems.Add("Shared Documents");
this.LSTResults.Items.Add(_lvItem3);

No comments: