none
Listview with multiple subitems RRS feed

  • Question

  • Hi All,

    How can i generate view exactly like this in C# Windows ListView control?

    P.N.: Columns "Movie" and "Class" has multiple values in place.....


    Jiten Patoliya Windows C# developer


    Sunday, September 23, 2012 6:38 AM

Answers

  • Hi,

    Ur ListView's ViewMode must be DetailsView,and then plz add columns and rows:

    Sample——Suppose there's ONLY a DetailsView onto ur WinForm:

    partial class Form1
        {
            /// <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.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
                "Decker",
                "20",
                "Clear PC"}, -1);
                System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] {
                "",
                "",
                "Do HomeWork"}, -1);
                System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem(new string[] {
                "Mary",
                "21",
                "Go to barbar\'s"}, -1);
                this.listView1 = new System.Windows.Forms.ListView();
                this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.SuspendLayout();
                // 
                // listView1
                // 
                this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
                this.columnHeader1,
                this.columnHeader4,
                this.columnHeader5});
                this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
                listViewItem1,
                listViewItem2,
                listViewItem3});
                this.listView1.Location = new System.Drawing.Point(42, 39);
                this.listView1.Name = "listView1";
                this.listView1.Size = new System.Drawing.Size(516, 331);
                this.listView1.TabIndex = 0;
                this.listView1.UseCompatibleStateImageBehavior = false;
                this.listView1.View = System.Windows.Forms.View.Details;
                // 
                // columnHeader1
                // 
                this.columnHeader1.Text = "Name";
                this.columnHeader1.Width = 141;
                // 
                // columnHeader4
                // 
                this.columnHeader4.Text = "Age";
                this.columnHeader4.Width = 114;
                // 
                // columnHeader5
                // 
                this.columnHeader5.Text = "Work";
                this.columnHeader5.Width = 208;
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(602, 425);
                this.Controls.Add(this.listView1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.ResumeLayout(false);
    
            }
    
            #endregion
    
            private System.Windows.Forms.ListView listView1;
            private System.Windows.Forms.ColumnHeader columnHeader1;
            private System.Windows.Forms.ColumnHeader columnHeader4;
            private System.Windows.Forms.ColumnHeader columnHeader5;
        }


    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    Sunday, September 23, 2012 7:23 AM
  • You can use ListView.DrawSubItem event to draw custom fill and drawings for ListView control.

    Below link should provide more insight into this.

    http://msdn.microsoft.com/en-us/library/989zcatz(v=vs.80).aspx


    Mark it as helpful if so!!! thanks, Mithilesh

    Sunday, September 23, 2012 7:23 PM

All replies

  • Hi,

    Ur ListView's ViewMode must be DetailsView,and then plz add columns and rows:

    Sample——Suppose there's ONLY a DetailsView onto ur WinForm:

    partial class Form1
        {
            /// <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.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
                "Decker",
                "20",
                "Clear PC"}, -1);
                System.Windows.Forms.ListViewItem listViewItem2 = new System.Windows.Forms.ListViewItem(new string[] {
                "",
                "",
                "Do HomeWork"}, -1);
                System.Windows.Forms.ListViewItem listViewItem3 = new System.Windows.Forms.ListViewItem(new string[] {
                "Mary",
                "21",
                "Go to barbar\'s"}, -1);
                this.listView1 = new System.Windows.Forms.ListView();
                this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
                this.SuspendLayout();
                // 
                // listView1
                // 
                this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
                this.columnHeader1,
                this.columnHeader4,
                this.columnHeader5});
                this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
                listViewItem1,
                listViewItem2,
                listViewItem3});
                this.listView1.Location = new System.Drawing.Point(42, 39);
                this.listView1.Name = "listView1";
                this.listView1.Size = new System.Drawing.Size(516, 331);
                this.listView1.TabIndex = 0;
                this.listView1.UseCompatibleStateImageBehavior = false;
                this.listView1.View = System.Windows.Forms.View.Details;
                // 
                // columnHeader1
                // 
                this.columnHeader1.Text = "Name";
                this.columnHeader1.Width = 141;
                // 
                // columnHeader4
                // 
                this.columnHeader4.Text = "Age";
                this.columnHeader4.Width = 114;
                // 
                // columnHeader5
                // 
                this.columnHeader5.Text = "Work";
                this.columnHeader5.Width = 208;
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(602, 425);
                this.Controls.Add(this.listView1);
                this.Name = "Form1";
                this.Text = "Form1";
                this.ResumeLayout(false);
    
            }
    
            #endregion
    
            private System.Windows.Forms.ListView listView1;
            private System.Windows.Forms.ColumnHeader columnHeader1;
            private System.Windows.Forms.ColumnHeader columnHeader4;
            private System.Windows.Forms.ColumnHeader columnHeader5;
        }


    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

    Sunday, September 23, 2012 7:23 AM
  • You can use ListView.DrawSubItem event to draw custom fill and drawings for ListView control.

    Below link should provide more insight into this.

    http://msdn.microsoft.com/en-us/library/989zcatz(v=vs.80).aspx


    Mark it as helpful if so!!! thanks, Mithilesh

    Sunday, September 23, 2012 7:23 PM
  • Yes this is the one way to achieve this.

    i am looking for other way to implement and make sure on changing text(Rate, Active) of subitem i get showdate, movie and calss values to perform db operation...


    Jiten Patoliya Windows C# developer

    Wednesday, September 26, 2012 4:58 AM