zoukankan      html  css  js  c++  java
  • listView控件演示程序

    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;

    namespace List
    {
     /// <summary>
     /// Form1 的摘要说明。
     /// </summary>
     public class Form1 : System.Windows.Forms.Form
     {
      p rivate System.Windows.Forms.ListView listView1;
      p rivate System.Windows.Forms.Button button1;
      p rivate System.Windows.Forms.Button button2;
      p rivate System.Windows.Forms.Button button3;
      p rivate System.Windows.Forms.Button button4;
      p rivate System.Windows.Forms.ImageList imageList1;
      p rivate System.Windows.Forms.ImageList imageList2;
      p rivate System.Windows.Forms.ColumnHeader columnHeader1;
      p rivate System.Windows.Forms.ColumnHeader columnHeader2;
      p rivate System.Windows.Forms.ColumnHeader columnHeader3;
      p rivate System.Windows.Forms.Button button5;
      p rivate System.ComponentModel.IContainer components;

      public Form1()
      {
       //
       // Windows 窗体设计器支持所必需的
       //
       InitializeComponent();

       //
       // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
       //
      }

      /// <summary>
      /// 清理所有正在使用的资源。
      /// </summary>
      protected override void Dispose( bool disposing )
      {
       if( disposing )
       {
        if (components != null)
        {
         components.Dispose();
        }
       }
       base.Dispose( disposing );
      }

      #region Windows 窗体设计器生成的代码
      /// <summary>
      /// 设计器支持所需的方法 - 不要使用代码编辑器修改
      /// 此方法的内容。
      /// </summary>
      p rivate void InitializeComponent()
      {
       this.components = new System.ComponentModel.Container();
       System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {
                                  "罗斌",
                                  "计算机应用",
                                  "高等教育自学考试"}, -1);
       System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
       this.listView1 = new System.Windows.Forms.ListView();
       this.button1 = new System.Windows.Forms.Button();
       this.button2 = new System.Windows.Forms.Button();
       this.button3 = new System.Windows.Forms.Button();
       this.button4 = new System.Windows.Forms.Button();
       this.imageList1 = new System.Windows.Forms.ImageList(this.components);
       this.imageList2 = new System.Windows.Forms.ImageList(this.components);
       this.columnHeader1 = new System.Windows.Forms.ColumnHeader();
       this.columnHeader2 = new System.Windows.Forms.ColumnHeader();
       this.columnHeader3 = new System.Windows.Forms.ColumnHeader();
       this.button5 = new System.Windows.Forms.Button();
       this.SuspendLayout();
       //
       // listView1
       //
       this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
                          this.columnHeader1,
                          this.columnHeader2,
                          this.columnHeader3});
       this.listView1.Items.AddRange(new System.Windows.Forms.ListViewItem[] {
                           listViewItem1});
       this.listView1.LargeImageList = this.imageList1;
       this.listView1.Location = new System.Drawing.Point(8, 8);
       this.listView1.Name = "listView1";
       this.listView1.Size = new System.Drawing.Size(392, 152);
       this.listView1.SmallImageList = this.imageList2;
       this.listView1.TabIndex = 0;
       this.listView1.View = System.Windows.Forms.View.Details;
       //
       // button1
       //
       this.button1.Location = new System.Drawing.Point(8, 168);
       this.button1.Name = "button1";
       this.button1.Size = new System.Drawing.Size(80, 23);
       this.button1.TabIndex = 1;
       this.button1.Text = "大图标显示";
       this.button1.Click += new System.EventHandler(this.button1_Click);
       //
       // button2
       //
       this.button2.Location = new System.Drawing.Point(88, 168);
       this.button2.Name = "button2";
       this.button2.Size = new System.Drawing.Size(80, 23);
       this.button2.TabIndex = 2;
       this.button2.Text = "小图标显示";
       this.button2.Click += new System.EventHandler(this.button2_Click);
       //
       // button3
       //
       this.button3.Location = new System.Drawing.Point(168, 168);
       this.button3.Name = "button3";
       this.button3.Size = new System.Drawing.Size(88, 23);
       this.button3.TabIndex = 3;
       this.button3.Text = "详细资料显示";
       this.button3.Click += new System.EventHandler(this.button3_Click);
       //
       // button4
       //
       this.button4.Location = new System.Drawing.Point(256, 168);
       this.button4.Name = "button4";
       this.button4.Size = new System.Drawing.Size(64, 23);
       this.button4.TabIndex = 4;
       this.button4.Text = "增加新项";
       this.button4.Click += new System.EventHandler(this.button4_Click);
       //
       // 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;
       //
       // 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;
       //
       // columnHeader1
       //
       this.columnHeader1.Text = "  姓名";
       this.columnHeader1.Width = 87;
       //
       // columnHeader2
       //
       this.columnHeader2.Text = "学历及专业";
       this.columnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
       this.columnHeader2.Width = 120;
       //
       // columnHeader3
       //
       this.columnHeader3.Text = "毕业院校";
       this.columnHeader3.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
       this.columnHeader3.Width = 180;
       //
       // button5
       //
       this.button5.Location = new System.Drawing.Point(320, 168);
       this.button5.Name = "button5";
       this.button5.Size = new System.Drawing.Size(80, 23);
       this.button5.TabIndex = 5;
       this.button5.Text = "删除选择项";
       this.button5.Click += new System.EventHandler(this.button5_Click);
       //
       // Form1
       //
       this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
       this.ClientSize = new System.Drawing.Size(408, 198);
       this.Controls.Add(this.button5);
       this.Controls.Add(this.button4);
       this.Controls.Add(this.button3);
       this.Controls.Add(this.button2);
       this.Controls.Add(this.button1);
       this.Controls.Add(this.listView1);
       this.MaximizeBox = false;
       this.Name = "Form1";
       this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
       this.Text = "演示列表视图控件";
       this.Load += new System.EventHandler(this.Form1_Load);
       this.ResumeLayout(false);

      }
      #endregion

      /// <summary>
      /// 应用程序的主入口点。
      /// </summary>
      [STAThread]
      static void Main()
      {
       Application.Run(new Form1());
      }

      p rivate void Form1_Load(object sender, System.EventArgs e)
      {//初始化列表项数据
       int itemNumber=this.listView1.Items.Count;
       string[] subItem0={"王斌","计算机科学技术","武汉大学"};
       this.listView1.Items.Insert(itemNumber, new ListViewItem(subItem0));
       this.listView1.Items[itemNumber].ImageIndex=0; 
       string[] subItem1={"汪兰","财会电算化管理","西南财经大学"};
       this.listView1.Items.Insert(itemNumber, new ListViewItem(subItem1));
       this.listView1.Items[itemNumber].ImageIndex=1; 
       string[] subItem2={"汤波","计算机软件技术","上海交通大学"};
       this.listView1.Items.Insert(itemNumber, new ListViewItem(subItem2));
       this.listView1.Items[itemNumber].ImageIndex=2;     
      }

      p rivate void button4_Click(object sender, System.EventArgs e)
      {//增加化列表项数据
       int itemNumber=this.listView1.Items.Count;
       string[] subItem={"罗成","工业与民用建筑","重庆大学"};
       this.listView1.Items.Insert(itemNumber, new ListViewItem(subItem)); 
       this.listView1.Items[itemNumber].ImageIndex=2;     
      }

      p rivate void button5_Click(object sender, System.EventArgs e)
      {//删除已经选择的列表项数据
       for(int i=this.listView1.SelectedItems.Count-1; i>=0;i--)
       {
        ListViewItem item = this.listView1.SelectedItems[i];
        this.listView1.Items.Remove(item);
       }
      }

      p rivate void button1_Click(object sender, System.EventArgs e)
      {//以大图标方式显示列表项数据
       this.listView1.View=View.LargeIcon;
      }
      p rivate void button2_Click(object sender, System.EventArgs e)
      {//以小图标方式显示列表项数据
       this.listView1.View=View.SmallIcon;
      }
      p rivate void button3_Click(object sender, System.EventArgs e)
      {//以详细资料方式显示列表项数据
          this.listView1.View=View.Details;
      }
     }
    }

  • 相关阅读:
    「POJ 2699」The Maximum Number of Strong Kings
    「HNOI 2013」切糕
    「PKUSC 2018」真实排名
    「国家集训队 2009」最大收益
    「TJOI2015」线性代数
    「BZOJ 3280」小R的烦恼
    「SDOI 2017」新生舞会
    「六省联考 2017」寿司餐厅
    「TJOI 2013」循环格
    「TJOI 2013」攻击装置
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668416.html
Copyright © 2011-2022 走看看