listview加button怎么加?

时间:2022-06-17 21:09:36
listview加button怎么加?
这个控件是listview吧,怎么在某一列加button,而且是在点击某一行的时候才显示出来,就像图片这样。
谢谢

16 个解决方案

#1


定义模板列 然后把button拖进去就行了

#2


不难, 参考

#3


可以直接+吧

#4


#5


我觉得他更像 DataGridView(DataGrid)

#6


#7


引用 6 楼 wuyq11 的回复:
参考

谢谢,这里的很全,但是好像没有我要的这种效果的控件。

#8


留个记号,

#9


模板,拖进去!

#10


经典,收藏。。。

#11


定义模板,拖控件进去,然后写buttonclick事件

#12


引用 11 楼 loveapple543 的回复:
定义模板,拖控件进去,然后写buttonclick事件

这是应用程序

#13


        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);
        }

#14


引用 13 楼 qqiuzaihui 的回复:
C# codeprivate Button btn=new Button();privatevoid Form1_Load(object sender, EventArgs e)
        {
            ListViewItem[] lvs=new ListViewItem[3];
            lvs[0]=new ListViewItem(newstring[] {"行1列1","行1列2","" });
            lvs[1]=new ListViewItem(newstring[] {"行2列1","行2列2","" });
            lvs[2]=new ListViewItem(newstring[] {"行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);
        }privatevoid 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;
            }
        }privatevoid button_Click(object sender, EventArgs e)
        {
            MessageBox.Show(this.listView1.SelectedItems[0].SubItems[0].Text);
        }

谢谢这位。

#15


可以拖进一个button控件,然后在listviewitems-click事件里写相应的操作!

#16


谢谢分享

#1


定义模板列 然后把button拖进去就行了

#2


不难, 参考

#3


可以直接+吧

#4


#5


我觉得他更像 DataGridView(DataGrid)

#6


#7


引用 6 楼 wuyq11 的回复:
参考

谢谢,这里的很全,但是好像没有我要的这种效果的控件。

#8


留个记号,

#9


模板,拖进去!

#10


经典,收藏。。。

#11


定义模板,拖控件进去,然后写buttonclick事件

#12


引用 11 楼 loveapple543 的回复:
定义模板,拖控件进去,然后写buttonclick事件

这是应用程序

#13


        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);
        }

#14


引用 13 楼 qqiuzaihui 的回复:
C# codeprivate Button btn=new Button();privatevoid Form1_Load(object sender, EventArgs e)
        {
            ListViewItem[] lvs=new ListViewItem[3];
            lvs[0]=new ListViewItem(newstring[] {"行1列1","行1列2","" });
            lvs[1]=new ListViewItem(newstring[] {"行2列1","行2列2","" });
            lvs[2]=new ListViewItem(newstring[] {"行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);
        }privatevoid 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;
            }
        }privatevoid button_Click(object sender, EventArgs e)
        {
            MessageBox.Show(this.listView1.SelectedItems[0].SubItems[0].Text);
        }

谢谢这位。

#15


可以拖进一个button控件,然后在listviewitems-click事件里写相应的操作!

#16


谢谢分享