c#怎么给winform ListView 中添加 button

dyufei 2010-04-01 02:13:10
c#怎么给winform ListView 中添加 button?
...全文
1169 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
dyufei 2010-04-01
  • 打赏
  • 举报
回复
只能通过坐标来控制 button 的位置吗?

有没有办法直接添加到 Items 中?

dyufei 2010-04-01
  • 打赏
  • 举报
回复
有什么办法嘛?
winform ListView 中添加 button?
herty 2010-04-01
  • 打赏
  • 举报
回复
this.listView1.Controls.Add(button2);
是Controls 不是 Container
xu56180825 2010-04-01
  • 打赏
  • 举报
回复
因为他不是容器。
dyufei 2010-04-01
  • 打赏
  • 举报
回复
Button ItemButton = new Button();
ItemButton.Text = "test";
ItemButton.Location = new Point(100,100);

添加的时候 抛出异常 Object reference not set to an instance of an object.

this.listView1.Container.Add(ItemButton);

这是为什么啊?
herty 2010-04-01
  • 打赏
  • 举报
回复

public partial class FormTest :NewFormTest.NewForm
{
private Button button2 = new Button();
public FormTest()
{
InitializeComponent();
button1.Text = "新增的";
button1.Location = new Point(30, 30);
this.listView1.Controls.Add(button2);
}
}
dyufei 2010-04-01
  • 打赏
  • 举报
回复
没有人知道吗?

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧