日期:2014-05-18  浏览次数:20865 次

listview加button怎么加?

这个控件是listview吧,怎么在某一列加button,而且是在点击某一行的时候才显示出来,就像图片这样。
谢谢

------解决方案--------------------
不难,参考
------解决方案--------------------
参考2
------解决方案--------------------
参考
------解决方案--------------------
C# code
        private Button btn = new Button();
        private void Form1_Load(object sender, EventArgs e)
        {
            ListViewItem[] lvs = new ListViewItem[3];
            lvs[0] = new ListViewItem(new string[] { "行1列1", "行1列2", "" });
            lvs[1]=new ListViewItem(new string[] { "行2列1", "行2列2", "" });
            lvs[2]=new ListViewItem(new string[] { "行3列1", "行3列2", "" });
            this.listView1.Items.AddRange(lvs);

            btn.Visible=false;
            btn.Text = "...";
            btn.Click += this.button_Click;
            this.listView1.Controls.Add(btn);
            this.btn.Size = new Size(this.listView1.Items[0].SubItems[2].Bounds.Width,
                this.listView1.Items[0].SubItems[2].Bounds.Height);
        }
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.listView1.SelectedItems.Count > 0)
            {
                this.btn.Location = new Point(this.listView1.SelectedItems[0].SubItems[2].Bounds.Left,
                    this.listView1.SelectedItems[0].SubItems[2].Bounds.Top);
                this.btn.Visible = true;
            }
        }
        private void button_Click(object sender, EventArgs e)
        {
            MessageBox.Show(this.listView1.SelectedItems[0].SubItems[0].Text);
        }