|
-
May 9th, 2010, 09:12 PM
#1
Swapping controls in TableLayoutPanel
Hi,
Basically I want to be able to drag drop controls inside the table layout panel where the control in the cell where i drop to swap position with the control where i drag from. I already managed to do the drag and drop part, but it doesn't swap position!
I have the table layout panel created using the form designer and the cells populated with checkbox controls (which i also created using the form designer). I want to be able to drag and drop the checkbox controls (swapping the controls by doing so) within the table layout panel cells during runtime, just like what i am able to do using the form designer during design time. I already managed to drag and drop controls within the table layout panel, But my problem now is when i drag and drop a control over another cell, the original checkbox control in the cell doesn't swap position with control i am dragging over.
This is what i did inside the DrapDrop function.
Code:
private void tableLayoutPanel1_DragDrop(object sender, DragEventArgs e)
{
CheckBox cb = e.Data.GetData(typeof(CheckBox)) as CheckBox;
Point loc = this.tableLayoutPanel1.PointToClient(new Point(e.X, e.Y));
//detemine the cell location
int ColumnIndex = -1;
int RowIndex = -1;
int x = 0;
int y = 0;
while (ColumnIndex <= this.tableLayoutPanel1.ColumnCount)
{
if (loc.X < x)
{
break;
}
ColumnIndex++;
x += this.tableLayoutPanel1.GetColumnWidths()[ColumnIndex];
}
while (RowIndex <= this.tableLayoutPanel1.RowCount)
{
if (loc.Y < y)
{
break;
}
RowIndex++;
y += this.tableLayoutPanel1.GetRowHeights()[RowIndex];
}
this.tableLayoutPanel1.Controls.Add(cb, ColumnIndex, RowIndex);
//cb.Invalidate();
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|