有没有办法从 TableLayoutPanel 中的一行中删除所有控件?
我动态生成 TableLayoutPanel 的控件。我的每一行都有一个删除按钮。当我点击它时,该行必须被删除。
Dim removeBtn As New Button
AddHandler removeBtn.Click, AddressOf DeleteRow
tlp.Controls.Add(removeBtn, 5, rowCount)
我没有显示添加与上面类似的文本框的代码。我可以获得单击按钮的行号。使用它,如何从该行中删除所有控件。
Private Sub DeleteRow(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim currentRow As Integer = CType(CType(sender, Button).Parent, TableLayoutPanel).GetRow(CType(sender, Button))
'Using this currentRow, how to delete this Row
End Sub
I generate controls for a TableLayoutPanel dynamically. I have a delete button in each row. When I click that, that row has to be removed.
Dim removeBtn As New Button
AddHandler removeBtn.Click, AddressOf DeleteRow
tlp.Controls.Add(removeBtn, 5, rowCount)
I have not shown the code to add text boxes which are similar to above. I can get the row number of the clicked button. Using this, how to remove all controls from this row.
Private Sub DeleteRow(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim currentRow As Integer = CType(CType(sender, Button).Parent, TableLayoutPanel).GetRow(CType(sender, Button))
'Using this currentRow, how to delete this Row
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
基本上,您必须:
这是 VB。 NET 代码执行相同的操作。
这里有一个 C# 扩展方法可以为您完成此操作。
Basically you have to:
Here is the VB.NET code to do the same.
Here is a C# extension method that will do this for you.
除了 Johann 和 emaillenin 的答案之外,您还应该将以下行更改
为“To this
Empty fields”,如果没有检查 null,跨度控件也会在此处抛出错误。
In addition to Johann and emaillenin's answers you should change the following line
To this
Empty fields and also spanned controls will throw an error here if theres no check for null.
何必这么辛苦...
使用
tableLayoutpanel1.Controls.Clear()
这将清除表格面板的内容
Why this much hardwork...
Use
tableLayoutpanel1.Controls.Clear()
This will clear the contents of table panel