TableLayoutPanel控件动态删除一行,贴出来分享一下
2013-05-15 10:26
399 查看
private void btnDelSelect_Click(object sender, EventArgs e)
{
bool bOver = true;//删除结束标记
REPEAT:
if (tlpSelection.RowCount == 0) { return; }
//遍历tlpSelections
for (int i = 0; i < tlpSelection.RowCount; i++)
{
bOver = true;
Control ctl = tlpSelection.GetControlFromPosition(0, i);
if (ctl.GetType().ToString().Contains("RadioButton"))
{
RadioButton rb = (RadioButton)ctl;
if (rb.Checked)
{
bOver = false;//有勾选项就没有结束
tlpSelection.Controls.Remove(rb);
//将后面行往前面移
int iCnt = tlpSelection.RowCount - 1 - i;
for (int j = 0; j < iCnt; j++, i++)
{
Control ctlNext = tlpSelection.GetControlFromPosition(0, i+1);
tlpSelection.SetCellPosition(ctlNext, new TableLayoutPanelCellPosition(0, i));
}
//移除最后一行
tlpSelection.RowStyles.RemoveAt(tlpSelection.RowCount - 1);
tlpSelection.RowCount = tlpSelection.RowCount - 1;
break;//一行一行地删除
}
}
}
if (bOver == false)
{
goto REPEAT;//由于删除一行后,行数有了变化,for循环就得从新开始执行
}
}
{
bool bOver = true;//删除结束标记
REPEAT:
if (tlpSelection.RowCount == 0) { return; }
//遍历tlpSelections
for (int i = 0; i < tlpSelection.RowCount; i++)
{
bOver = true;
Control ctl = tlpSelection.GetControlFromPosition(0, i);
if (ctl.GetType().ToString().Contains("RadioButton"))
{
RadioButton rb = (RadioButton)ctl;
if (rb.Checked)
{
bOver = false;//有勾选项就没有结束
tlpSelection.Controls.Remove(rb);
//将后面行往前面移
int iCnt = tlpSelection.RowCount - 1 - i;
for (int j = 0; j < iCnt; j++, i++)
{
Control ctlNext = tlpSelection.GetControlFromPosition(0, i+1);
tlpSelection.SetCellPosition(ctlNext, new TableLayoutPanelCellPosition(0, i));
}
//移除最后一行
tlpSelection.RowStyles.RemoveAt(tlpSelection.RowCount - 1);
tlpSelection.RowCount = tlpSelection.RowCount - 1;
break;//一行一行地删除
}
}
}
if (bOver == false)
{
goto REPEAT;//由于删除一行后,行数有了变化,for循环就得从新开始执行
}
}
相关文章推荐
- c# winForm TableLayoutPanel学习 合并行的布局及动态增加删除内部控件
- c# winForm TableLayoutPanel学习 合并行的布局及动态增加删除内部控件
- C# TableLayoutPanel 添加、删除一行数据案例
- c# TableLayoutPanel控件应用 动态添加控件及事件
- c# TableLayoutPanel控件应用 动态添加控件及事件
- c# TableLayoutPanel控件应用 动态添加控件及事件
- c# TableLayoutPanel控件应用 动态添加控件及事件
- table动态添加删除一行
- 利用jquery给指定的table动态添加一行、删除一行
- 利用jquery给指定的table动态添加一行、删除一行
- 如何:在 TableLayoutPanel 控件中锚定和停靠子控件
- Asp.net使用repeater控件动态添加、删除一行
- 使用 TableLayoutPanel 控件设置窗体布局
- 利用jquery给指定的table动态添加一行、删除一行
- 如何改变TableLayoutPanel中之控件间的距离
- 利用jquery给指定的table动态添加一行、删除一行的方法
- 演练:使用 TableLayoutPanel 在 Windows 窗体上排列控件
- 利用jquery给指定的table动态添加一行、删除一行,复制,值不重复等操作
- 利用jquery给指定的table动态添加一行、删除一行
- C# 双击TableLayoutPanel中某个控件全屏显示,再次双击恢复原貌