Click here to Skip to main content
15,922,007 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is the code to move the rows and columns in tablelayout control,

C#
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)
{
 
// MessageBox.Show(ex.ToString());
}
}


This is the code to get the row and column value by user during runtime,

C#
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...
Posted
Updated 28-Nov-11 18:57pm
v3
Comments
JF2015 29-Nov-11 0:24am    
Added code formatting.
[no name] 29-Nov-11 0:57am    
EDIT: Added "code" tag
srinivasan_indian 29-Nov-11 1:00am    
Are u clear with my issue now sir?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900