Click here to Skip to main content
15,891,033 members
Articles / Desktop Programming / Windows Forms

ListView Group Sorter

Rate me:
Please Sign up or sign in to vote.
5.00/5 (9 votes)
17 Aug 2009CPOL 80.2K   3.8K   61  
An easy to use ListView group sorter (very simple).
namespace LVGSorter
{
    partial class frmmain
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (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()
        {
            System.Windows.Forms.ListViewGroup listViewGroup5 = new System.Windows.Forms.ListViewGroup("Director", System.Windows.Forms.HorizontalAlignment.Left);
            System.Windows.Forms.ListViewGroup listViewGroup6 = new System.Windows.Forms.ListViewGroup("Department Manager", System.Windows.Forms.HorizontalAlignment.Left);
            System.Windows.Forms.ListViewGroup listViewGroup7 = new System.Windows.Forms.ListViewGroup("Supporter", System.Windows.Forms.HorizontalAlignment.Left);
            System.Windows.Forms.ListViewGroup listViewGroup8 = new System.Windows.Forms.ListViewGroup("Employees", System.Windows.Forms.HorizontalAlignment.Left);
            System.Windows.Forms.ListViewItem listViewItem7 = new System.Windows.Forms.ListViewItem("James");
            System.Windows.Forms.ListViewItem listViewItem8 = new System.Windows.Forms.ListViewItem("Sacha");
            System.Windows.Forms.ListViewItem listViewItem9 = new System.Windows.Forms.ListViewItem("Tina");
            System.Windows.Forms.ListViewItem listViewItem10 = new System.Windows.Forms.ListViewItem("Martin");
            System.Windows.Forms.ListViewItem listViewItem11 = new System.Windows.Forms.ListViewItem("Poul");
            System.Windows.Forms.ListViewItem listViewItem12 = new System.Windows.Forms.ListViewItem("Mikey");
            this.listView1 = new System.Windows.Forms.ListView();
            this.c_header1 = new System.Windows.Forms.ColumnHeader();
            this.c_header2 = new System.Windows.Forms.ColumnHeader();
            this.c_header3 = new System.Windows.Forms.ColumnHeader();
            this.bnt_ascending = new System.Windows.Forms.Button();
            this.bnt_descending = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // listView1
            // 
            this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
            this.c_header1,
            this.c_header2,
            this.c_header3});
            listViewGroup5.Header = "Director";
            listViewGroup5.Name = "listViewGroup1";
            listViewGroup6.Header = "Department Manager";
            listViewGroup6.Name = "listViewGroup2";
            listViewGroup7.Header = "Supporter";
            listViewGroup7.Name = "listViewGroup3";
            listViewGroup8.Header = "Employees";
            listViewGroup8.Name = "listViewGroup4";
            this.listView1.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] {
            listViewGroup5,
            listViewGroup6,
            listViewGroup7,
            listViewGroup8});
            listViewItem7.Group = listViewGroup5;
            listViewItem8.Group = listViewGroup6;
            listViewItem9.Group = listViewGroup7;
            listViewItem10.Group = listViewGroup8;
            listViewItem11.Group = listViewGroup7;
            listViewItem12.Group = listViewGroup8;
            this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
            listViewItem7,
            listViewItem8,
            listViewItem9,
            listViewItem10,
            listViewItem11,
            listViewItem12});
            this.listView1.Location = new System.Drawing.Point(12, 12);
            this.listView1.Name = "listView1";
            this.listView1.Size = new System.Drawing.Size(421, 240);
            this.listView1.TabIndex = 0;
            this.listView1.UseCompatibleStateImageBehavior = false;
            this.listView1.View = System.Windows.Forms.View.Details;
            // 
            // c_header1
            // 
            this.c_header1.Text = "First Name";
            this.c_header1.Width = 112;
            // 
            // c_header2
            // 
            this.c_header2.Text = "Last Name";
            this.c_header2.Width = 124;
            // 
            // c_header3
            // 
            this.c_header3.Text = "Title";
            this.c_header3.Width = 139;
            // 
            // bnt_ascending
            // 
            this.bnt_ascending.Location = new System.Drawing.Point(439, 12);
            this.bnt_ascending.Name = "bnt_ascending";
            this.bnt_ascending.Size = new System.Drawing.Size(88, 23);
            this.bnt_ascending.TabIndex = 1;
            this.bnt_ascending.Text = "Ascending";
            this.bnt_ascending.UseVisualStyleBackColor = true;
            this.bnt_ascending.Click += new System.EventHandler(this.bnt_ascending_Click);
            // 
            // bnt_descending
            // 
            this.bnt_descending.Location = new System.Drawing.Point(439, 41);
            this.bnt_descending.Name = "bnt_descending";
            this.bnt_descending.Size = new System.Drawing.Size(88, 23);
            this.bnt_descending.TabIndex = 2;
            this.bnt_descending.Text = "Descending";
            this.bnt_descending.UseVisualStyleBackColor = true;
            this.bnt_descending.Click += new System.EventHandler(this.bnt_descending_Click);
            // 
            // frmmain
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(539, 264);
            this.Controls.Add(this.bnt_descending);
            this.Controls.Add(this.bnt_ascending);
            this.Controls.Add(this.listView1);
            this.Name = "frmmain";
            this.Text = "ListView Group Sorting Class Demo by Paw Jershauge";
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.ListView listView1;
        private System.Windows.Forms.ColumnHeader c_header1;
        private System.Windows.Forms.ColumnHeader c_header2;
        private System.Windows.Forms.ColumnHeader c_header3;
        private System.Windows.Forms.Button bnt_ascending;
        private System.Windows.Forms.Button bnt_descending;
    }
}

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
Software Developer
Denmark Denmark

Comments and Discussions