This is the code to move the rows and columns in tablelayout control,
private void tableLayoutPanel1_MouseMove(object sender, MouseEventArgs e)
{
try
{
if(resizing )
{
if (rbColumn.Checked)
{
columnStyles[GColumn].SizeType =
SizeType.Absolute;
columnStyles[GColumn].Width += e.X - columnStyles[GColumn].Width;
}
else
{
rowStyles[GRow].SizeType =
SizeType.Absolute;
rowStyles[GRow].Height += e.Y - rowStyles[GRow].Height ;
}
}
}
catch (Exception ex)
{
}
}
This is the code to get the row and column value by user during runtime,
private void tableLayoutPanel1_MouseClick(object sender, MouseEventArgs e)
{
try
{
int Row = 0;
int VSpace = 0;
foreach (int h in tableLayoutPanel1.GetRowHeights())
{
int Column = 0;
int HSpace = 0;
foreach (int w in tableLayoutPanel1.GetColumnWidths())
{
Rectangle Rect = new Rectangle(HSpace, VSpace, w, h);
if ((Rect.Contains(e.Location)))
{
GColumn = Column;
GRow = Row;
MessageBox.Show("Row Value = " + Row.ToString() + " " + "Column Value = " + Column.ToString(), "TableLayoutPanel", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
HSpace += w;
Column += 1;
}
VSpace += h;
Row += 1;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString ());
}
}
Explanation:
Check my code. In that,
tableLayoutPanel1_MouseClick
event, if the user clicks any row or column, i am getting the row and column value during runtime..(Refer my code)
With the help of this row and column value, In
tableLayoutPanel1_MouseMove
event i am moving the specific row and column during runtime..(Refer my code)All the process done during runtime.
Now what my problem is,if I click 2 row and 3 column means, it is moving correctly. But 4th,5th and so on... columns are also moving.(Refer my code)
I just want to move only the 3rd column. Help me...