Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / C#

C# List View v1.3

Rate me:
Please Sign up or sign in to vote.
4.90/5 (168 votes)
2 Mar 2004CPOL13 min read 2.1M   55.8K   434  
A fully featured completely managed C# ListView.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using GlacialComponents.Controls;

namespace TestList1._2
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.TabControl tabControl1;
		private System.Windows.Forms.TabPage tabPage2;
		private GlacialComponents.Controls.GlacialList glacialList3;
		private System.Windows.Forms.ImageList imageList2;
		private System.Windows.Forms.TabPage tabPage1;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			GlacialComponents.Controls.GLColumn glColumn1 = new GlacialComponents.Controls.GLColumn();
			GlacialComponents.Controls.GLColumn glColumn2 = new GlacialComponents.Controls.GLColumn();
			GlacialComponents.Controls.GLColumn glColumn3 = new GlacialComponents.Controls.GLColumn();
			GlacialComponents.Controls.GLColumn glColumn4 = new GlacialComponents.Controls.GLColumn();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.tabControl1 = new System.Windows.Forms.TabControl();
			this.imageList2 = new System.Windows.Forms.ImageList(this.components);
			this.tabPage2 = new System.Windows.Forms.TabPage();
			this.glacialList3 = new GlacialComponents.Controls.GlacialList();
			this.tabPage1 = new System.Windows.Forms.TabPage();
			this.tabControl1.SuspendLayout();
			this.tabPage2.SuspendLayout();
			this.SuspendLayout();
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tabControl1
			// 
			this.tabControl1.Controls.Add(this.tabPage2);
			this.tabControl1.Controls.Add(this.tabPage1);
			this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.tabControl1.Location = new System.Drawing.Point(0, 0);
			this.tabControl1.Name = "tabControl1";
			this.tabControl1.SelectedIndex = 0;
			this.tabControl1.Size = new System.Drawing.Size(576, 158);
			this.tabControl1.TabIndex = 1;
			// 
			// imageList2
			// 
			this.imageList2.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList2.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList2.ImageStream")));
			this.imageList2.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// tabPage2
			// 
			this.tabPage2.Controls.Add(this.glacialList3);
			this.tabPage2.Location = new System.Drawing.Point(4, 22);
			this.tabPage2.Name = "tabPage2";
			this.tabPage2.Size = new System.Drawing.Size(568, 132);
			this.tabPage2.TabIndex = 1;
			this.tabPage2.Text = "XP Stylin";
			// 
			// glacialList3
			// 
			this.glacialList3.AllowColumnResize = true;
			this.glacialList3.AllowMultiselect = true;
			this.glacialList3.AlternateBackground = System.Drawing.Color.DarkGreen;
			this.glacialList3.AlternatingColors = false;
			this.glacialList3.AutoHeight = false;
			this.glacialList3.AutoSort = true;
			this.glacialList3.BackColor = System.Drawing.SystemColors.ControlLightLight;
			glColumn1.ControlType = GlacialComponents.Controls.ColumnControlTypes.None;
			glColumn1.ImageIndex = 0;
			glColumn1.LastSortState = GlacialComponents.Controls.ColumnSortState.SortedUp;
			glColumn1.Name = "Band";
			glColumn1.Text = "Band";
			glColumn1.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
			glColumn1.Width = 100;
			glColumn2.ControlType = GlacialComponents.Controls.ColumnControlTypes.None;
			glColumn2.ImageIndex = 1;
			glColumn2.LastSortState = GlacialComponents.Controls.ColumnSortState.SortedUp;
			glColumn2.Name = "Progress";
			glColumn2.Text = "Progress";
			glColumn2.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
			glColumn2.Width = 150;
			glColumn3.ControlType = GlacialComponents.Controls.ColumnControlTypes.None;
			glColumn3.ImageIndex = 2;
			glColumn3.LastSortState = GlacialComponents.Controls.ColumnSortState.SortedUp;
			glColumn3.Name = "Rating";
			glColumn3.Text = "Rating";
			glColumn3.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
			glColumn3.Width = 90;
			glColumn4.ControlType = GlacialComponents.Controls.ColumnControlTypes.None;
			glColumn4.ImageIndex = 3;
			glColumn4.LastSortState = GlacialComponents.Controls.ColumnSortState.SortedUp;
			glColumn4.Name = "Source";
			glColumn4.Text = "Source";
			glColumn4.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
			glColumn4.Width = 500;
			this.glacialList3.Columns.AddRange(new GlacialComponents.Controls.GLColumn[] {
																							 glColumn1,
																							 glColumn2,
																							 glColumn3,
																							 glColumn4});
			this.glacialList3.Dock = System.Windows.Forms.DockStyle.Fill;
			this.glacialList3.FocusedItem = null;
			this.glacialList3.FullRowSelect = true;
			this.glacialList3.GLGridLines = GlacialComponents.Controls.GLGridStyles.gridSolid;
			this.glacialList3.GridColor = System.Drawing.Color.Gray;
			this.glacialList3.HeaderHeight = 22;
			this.glacialList3.HeaderStyle = GlacialComponents.Controls.GLHeaderStyles.XP;
			this.glacialList3.HeaderVisible = true;
			this.glacialList3.HeaderWordWrap = false;
			this.glacialList3.HotColumnIndex = -1;
			this.glacialList3.HotItemIndex = -1;
			this.glacialList3.HotTracking = true;
			this.glacialList3.HotTrackingColor = System.Drawing.Color.LightGray;
			this.glacialList3.ImageList = this.imageList1;
			this.glacialList3.ItemHeight = 22;
			this.glacialList3.ItemWordWrap = false;
			this.glacialList3.Location = new System.Drawing.Point(0, 0);
			this.glacialList3.MaxHeight = 20;
			this.glacialList3.Name = "glacialList3";
			this.glacialList3.SelectedTextColor = System.Drawing.Color.White;
			this.glacialList3.SelectionColor = System.Drawing.Color.DarkBlue;
			this.glacialList3.ShowBorder = true;
			this.glacialList3.ShowFocusRect = true;
			this.glacialList3.Size = new System.Drawing.Size(568, 132);
			this.glacialList3.SortIndex = 0;
			this.glacialList3.SuperFlatHeaderColor = System.Drawing.Color.White;
			this.glacialList3.TabIndex = 0;
			this.glacialList3.Text = "glacialList3";
			// 
			// tabPage1
			// 
			this.tabPage1.Location = new System.Drawing.Point(4, 22);
			this.tabPage1.Name = "tabPage1";
			this.tabPage1.Size = new System.Drawing.Size(568, 132);
			this.tabPage1.TabIndex = 2;
			this.tabPage1.Text = "tabPage1";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(576, 158);
			this.Controls.Add(this.tabControl1);
			this.Name = "Form1";
			this.Text = "Form1";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.tabControl1.ResumeLayout(false);
			this.tabPage2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.EnableVisualStyles();
			Application.Run(new Form1());
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
			GLItem item;
			ProgressBar pb;
			//ComboBox cb;
			CheckBox chkbox;


			item = this.glacialList3.Items.Add( "Metalica" );
			chkbox = new CheckBox();
			chkbox.FlatStyle = FlatStyle.System;
			chkbox.Text = "Metalica";
			item.SubItems[0].Control = chkbox;
			item.SubItems[1].ForceText = true;
			item.SubItems[1].Text = "Done";
			item.SubItems[2].Text = "9";
			item.SubItems[3].Text = "http://www.fakeurl.com/nothingtoseehere";


			item = this.glacialList3.Items.Add( "Korn" );
			chkbox = new CheckBox();
			chkbox.FlatStyle = FlatStyle.System;
			chkbox.Text = "Korn";
			item.SubItems[0].Control = chkbox;

			pb = new ProgressBar();
			item.SubItems[1].Control = pb;
			pb.Value = 34;
			item.SubItems[2].Text = "8";
			item.SubItems[3].Text = "http://www.fakeurl.com/nothingtoseehere";


			item = this.glacialList3.Items.Add( "Limp Bizkit" );
			chkbox = new CheckBox();
			chkbox.FlatStyle = FlatStyle.System;
			chkbox.Text = "Limp Bizkit";
			item.SubItems[0].Control = chkbox;

			pb = new ProgressBar();
			item.SubItems[1].Control = pb;
			pb.Value = 56;
			item.SubItems[2].Text = "6";
			item.SubItems[3].Text = "http://www.fakeurl.com/nothingtoseehere";


			item = this.glacialList3.Items.Add( "Hot IO" );
			chkbox = new CheckBox();
			chkbox.FlatStyle = FlatStyle.System;
			chkbox.Text = "Hot IO";
			item.SubItems[0].Control = chkbox;

			pb = new ProgressBar();
			item.SubItems[1].Control = pb;
			pb.Value = 11;
			item.SubItems[2].Text = "10";


			item = this.glacialList3.Items.Add( "J.Lo" );
			chkbox = new CheckBox();
			chkbox.FlatStyle = FlatStyle.System;
			chkbox.Text = "J.Lo";
			item.SubItems[0].Control = chkbox;

			item.SubItems[1].ForceText = true;
			item.SubItems[1].Text = "Rejected";
			item.SubItems[2].Text = "0";
			item.SubItems[3].Text = "http://www.fakeurl.com/nothingtoseehere";

			item = this.glacialList3.Items.Add( "Chevelle" );
			chkbox = new CheckBox();
			chkbox.FlatStyle = FlatStyle.System;
			chkbox.Text = "Chevelle";
			item.SubItems[0].Control = chkbox;

			item.SubItems[1].ForceText = true;
			item.SubItems[1].Text = "Done";
			item.SubItems[2].Text = "8";
			item.SubItems[3].Text = "http://www.fakeurl.com/nothingtoseehere";


			item = this.glacialList3.Items.Add( "MxPx" );
			chkbox = new CheckBox();
			chkbox.FlatStyle = FlatStyle.System;
			chkbox.Text = "MxPx";
			item.SubItems[0].Control = chkbox;

			item.SubItems[1].ForceText = true;
			item.SubItems[1].Text = "Done";
			item.SubItems[2].Text = "2";
			item.SubItems[3].Text = "http://www.fakeurl.com/nothingtoseehere";


			//this.glacialList1.Items.SelectedItems
#if false
			for ( int x=0; x<1; x++ )
			{
				item = this.glacialList1.Items.Add( "Florida Marlins" );
				item.SubItems[1].Text = "";
				item.SubItems[2].Text = "Delayed";
				item.SubItems[2].BackColor = Color.LightCoral;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";
				cb = new ComboBox();
				cb.Items.Add( "test1" );
				cb.Items.Add( "test2" );
				cb.Items.Add( "test3" );
				//cb.PreferredHeight = 20;

				item.SubItems[1].Control = cb;
				//cb.Visible = true; // kludge


				pb = new ProgressBar();
				item.SubItems[3].Control = pb;
				pb.Value = 34;


				item = this.glacialList1.Items.Add( "Tampa Bay" );
				item.SubItems[1].Text = "3:35";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";
				item.SubItems[0].ImageIndex = 0;

				pb = new ProgressBar();
				pb.Value = 83;
				item.SubItems[3].Control = pb;

				TextBox tb = new TextBox();
				item.SubItems[1].Control = tb;
				item.SubItems[0].ImageIndex = 1;

				item = this.glacialList1.Items.Add( "Detroit" );
				item.SubItems[1].Text = "7:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				pb.Value = 10;
				item.SubItems[3].Control = pb;

				item.SubItems[0].ImageIndex = 2;

				item = this.glacialList1.Items.Add( "Los Angeles" );
				item.SubItems[1].Text = "7:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				pb.Value = 98;
				item.SubItems[3].Control = pb;

				DateTimePicker dtc = new DateTimePicker();
				item.SubItems[1].Control = dtc;

				item.SubItems[0].ImageIndex = 3;

				item = this.glacialList1.Items.Add( "Saint Louis" );
				item.SubItems[1].Text = "7:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				pb.Value = 59;
				item.SubItems[3].Control = pb;

				item.SubItems[0].ImageIndex = 7;

				item = this.glacialList1.Items.Add( "Pittsburg" );
				item.SubItems[1].Text = "7:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				item.SubItems[3].Control = pb;

				item.SubItems[0].ImageIndex = 5;

				item = this.glacialList1.Items.Add( "Texas" );
				item.SubItems[1].Text = "8:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				pb.Value = 61;
				item.SubItems[3].Control = pb;

				item.SubItems[0].ImageIndex = 7;

				item = this.glacialList1.Items.Add( "Houston" );
				item.SubItems[1].Text = "8:05";
				item.SubItems[2].Text = "Delayed";
				item.SubItems[2].BackColor = Color.LightCoral;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				item.SubItems[3].Control = pb;


				item = this.glacialList1.Items.Add( "Chicago" );
				item.SubItems[1].Text = "7:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				item.SubItems[3].Control = pb;


				item = this.glacialList1.Items.Add( "San Francisco" );
				item.SubItems[1].Text = "7:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				item.SubItems[3].Control = pb;


				item = this.glacialList1.Items.Add( "Orange County" );
				item.SubItems[1].Text = "7:05";
				item.SubItems[2].Text = "Delayed";
				item.SubItems[2].BackColor = Color.LightCoral;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				item.SubItems[3].Control = pb;


				item = this.glacialList1.Items.Add( "Tulsa" );
				item.SubItems[1].Text = "7:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				item.SubItems[3].Control = pb;


				item = this.glacialList1.Items.Add( "Dallas" );
				item.SubItems[1].Text = "8:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				item.SubItems[3].Control = pb;


				item = this.glacialList1.Items.Add( "London" );
				item.SubItems[1].Text = "8:05";
				item.SubItems[2].Text = "Pregame";
				item.SubItems[2].BackColor = Color.LightGoldenrodYellow;
				item.SubItems[3].Text = "Audio";
				item.SubItems[4].Text = "Audio";

				pb = new ProgressBar();
				item.SubItems[3].Control = pb;
			}
#endif
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			Form2 frm = new Form2();
			frm.ShowDialog();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Primary Architects, Inc.
United States United States
I started my programming career in the late 80's with video games and have since written games on the AppleIIgs, SNES, Saturn, Playstation, and PC. After leaving the games industry and joining the ranks of consultants I began doing a lot of work with client/server applications, data movement, and communications. I've also become a recent convert to the XP principles of software development. Despite my defection to the business world I am still an avid gamer and I can be found on the gamezone most weekends slugging it out with others in the various online games there.

I currently live in Utah where I run PA (enterprise architecture consulting firm) and occasionally guest speak at architect forums. I mountain bike (badly), golf (very badly), and have fun (often).

Comments and Discussions