TableLayoutPanel 常见操作
来源:互联网 发布:淘宝交易纠纷处理 编辑:程序博客网 时间:2024/05/21 09:47
'm using the the TableLayoutPanel for a new WinForms 2.0 app and love the way it mimics HTML tables in terms of layout, automatic resizing etc.... But, incredibly, there seems to be no way to dynamically add or delete rows from this container at runtime. Has anyone figured out how to do this? What would be the technical/architectural argument for Microsoft's not exposing Rows and Columns collections in this control that can be managed programmatically? IMO....without this seemingly basic feature, the potential uses for this control diminish greatly.
Mike Morris
Friday, January 06, 2006
Friday, January 06, 2006
Deleting... Approving...
Have you tried MyTableLayoutPanel.Controls.Add(control,colnum,rownum) ?
GiorgioG
Friday, January 06, 2006
Friday, January 06, 2006
Deleting... Approving...
Anything that can be done at design time can also be done at run time. Look at the InitializeComponent method for clues.
Turtle Rustler
Friday, January 06, 2006
Friday, January 06, 2006
Deleting... Approving...
Hi,
to add rows and columns dynamical simply set the column or row size! You then have to add specific attributes for the columns and rows based using the ColumnStyles and RowStyles properties. The code below illustrates:
table.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
table.Width = 210;
table.Height = 210;
table.RowCount = 20;
table.ColumnCount = 20;
for (int i = 0; i < 20; i++)
{
table.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 10));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 10));
}
to add rows and columns dynamical simply set the column or row size! You then have to add specific attributes for the columns and rows based using the ColumnStyles and RowStyles properties. The code below illustrates:
table.CellBorderStyle = TableLayoutPanelCellBorderStyle.Single;
table.Width = 210;
table.Height = 210;
table.RowCount = 20;
table.ColumnCount = 20;
for (int i = 0; i < 20; i++)
{
table.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, 10));
table.RowStyles.Add(new RowStyle(SizeType.Absolute, 10));
}
Jerod Edward Moemeka
Tuesday, January 10, 2006
Tuesday, January 10, 2006
Deleting... Approving...
Hey I just got the "delete" row working. You have to delete the controls in the row first then shift all the other controls up by one row. Try this to see if it will work for you. FYI I am using the tag to mark the control row id. Example:
protected void DeleteButton_Click(object sender, EventArgs e)
{
//MessageBox.Show("Line item delete pressed. Tag = " + ((Button)sender).Tag);
int iRowId = int.Parse(((Button)sender).Tag.ToString());
this.tlpBillItem.SuspendLayout();
Control c = null;
//delete current row controls
for (int j = 0; j < this.tlpBillItem.ColumnCount; j++)
{
c = this.tlpBillItem.GetControlFromPosition(j, iRowId);
if (c != null)
{
this.tlpBillItem.Controls.Remove(c);
}
}
//need to shift all controls up one row from delete point
TableLayoutPanelCellPosition controlPosition;
for (int i = iRowId; i < this.tlpBillItem.RowCount; i++)
{
for (int j = 0; j < this.tlpBillItem.ColumnCount; j++)
{
c = this.tlpBillItem.GetControlFromPosition(j, i + 1);
if (c == null)
break;
c.Tag = i;
controlPosition = new TableLayoutPanelCellPosition(j, i);
this.tlpBillItem.SetCellPosition(c, controlPosition);
}
}
//need to remove the row
this.tlpBillItem.RowCount--;
this.tlpBillItem.ResumeLayout(false);
this.tlpBillItem.PerformLayout();
}
protected void DeleteButton_Click(object sender, EventArgs e)
{
//MessageBox.Show("Line item delete pressed. Tag = " + ((Button)sender).Tag);
int iRowId = int.Parse(((Button)sender).Tag.ToString());
this.tlpBillItem.SuspendLayout();
Control c = null;
//delete current row controls
for (int j = 0; j < this.tlpBillItem.ColumnCount; j++)
{
c = this.tlpBillItem.GetControlFromPosition(j, iRowId);
if (c != null)
{
this.tlpBillItem.Controls.Remove(c);
}
}
//need to shift all controls up one row from delete point
TableLayoutPanelCellPosition controlPosition;
for (int i = iRowId; i < this.tlpBillItem.RowCount; i++)
{
for (int j = 0; j < this.tlpBillItem.ColumnCount; j++)
{
c = this.tlpBillItem.GetControlFromPosition(j, i + 1);
if (c == null)
break;
c.Tag = i;
controlPosition = new TableLayoutPanelCellPosition(j, i);
this.tlpBillItem.SetCellPosition(c, controlPosition);
}
}
//need to remove the row
this.tlpBillItem.RowCount--;
this.tlpBillItem.ResumeLayout(false);
this.tlpBillItem.PerformLayout();
}
Tony Nguyen
Friday, January 20, 2006
Friday, January 20, 2006
- TableLayoutPanel 常见操作
- TableLayoutPanel
- tableLayoutPanel使用方法
- TableLayoutPanel 不能获取焦点
- tableLayoutPanel: 表格布局面板
- TableLayoutPanel控件的使用
- 使用tablelayoutpanel布局
- 使用tablelayoutpanel布局
- TableLayoutPanel闪烁问题解决
- TableLayoutPanel删除行
- 解决TableLayoutPanel控件闪烁
- tableLayoutPanel的单元格设置
- 如何使tableLayoutPanel 不闪烁
- 如何使tableLayoutPanel 不闪烁
- C# TableLayoutPanel 绘制边框,防闪屏
- C# TableLayoutPanel控件的使用
- 常见公历日期操作
- 常见的SREng操作
- 让优先级问题远离我们!!!
- 程序运行过程中直接配置数据源
- oracle 学习(五)
- 繁忙的一天
- 逆蛇型矩阵(螺旋魔方矩阵)
- TableLayoutPanel 常见操作
- vc平台下 解决外部符号错误:_main,_WinMain@16,__beginthreadex
- One method to disable close button on title bar
- SAP 模块中文解释
- struts乱码解决
- 关于JAVA判断字符串是否数字
- (转)tomcat5中文问题解决
- Linux下文件的操作
- java多线程设计模式