Chinaunix首页 | 论坛 | 博客
  • 博客访问: 302388
  • 博文数量: 93
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 830
  • 用 户 组: 普通用户
  • 注册时间: 2016-02-25 10:44
个人简介

一杯茶,一台电脑

文章分类

全部博文(93)

文章存档

2018年(4)

2017年(57)

2016年(32)

分类: C#/.net

2016-08-15 23:42:26


  1. private Button btn = new Button();
  2.         private void Form1_Load(object sender, EventArgs e)
  3.         {
  4.             ListViewItem[] lvs = new ListViewItem[3];
  5.             lvs[0] = new ListViewItem(new string[] { "行1列1", "行1列2", "" });
  6.             lvs[1]=new ListViewItem(new string[] { "行2列1", "行2列2", "" });
  7.             lvs[2]=new ListViewItem(new string[] { "行3列1", "行3列2", "" });
  8.             this.listView1.Items.AddRange(lvs);

  9.             btn.Visible=false;
  10.             btn.Text = "...";
  11.             btn.Click += this.button_Click;
  12.             this.listView1.Controls.Add(btn);
  13.             this.btn.Size = new Size(this.listView1.Items[0].SubItems[2].Bounds.Width,
  14.                 this.listView1.Items[0].SubItems[2].Bounds.Height);
  15.         }
  16.         private void listView1_SelectedIndexChanged(object sender, EventArgs e)
  17.         {
  18.             if (this.listView1.SelectedItems.Count > 0)
  19.             {
  20.                 this.btn.Location = new Point(this.listView1.SelectedItems[0].SubItems[2].Bounds.Left,
  21.                     this.listView1.SelectedItems[0].SubItems[2].Bounds.Top);
  22.                 this.btn.Visible = true;
  23.             }
  24.         }
  25.         private void button_Click(object sender, EventArgs e)
  26.         {
  27.             MessageBox.Show(this.listView1.SelectedItems[0].SubItems[0].Text);
  28.         }

阅读(3448) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~