473,461 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Delete Rows from a TableLayoutPanel

Hi,

I am trying to delete rows from a TableLayoutPanel at Runtime. I tried
editing the RowStyles collection but doesn't do what I want it to. I
have a table with 10 rows. I want to delete rows 2 to 10 at runtime,
keeping the first row unchanged.

Can this be done?

Thanks,
Avanti Ketkar

Jul 28 '06 #1
2 30730
Hi,

I was struggling with the same problem today.
In the first column of my TableLayoutPanel, I'm showing a checkbox.
When the user is checking it, a new row needs to be created.
When the user is unchecking it, the row containing the checkbox should be
removed.

Logically to remove a row in the TableLayoutPanel, I would think to do
something like this:
tableLayoutPanel.RowStyles.RemoveAt(index);

But I found out this is not enough.
You need to clear the controls for that given row as well!
tableLayoutPanel.Controls.RemoveAt(...);
tableLayoutPanel.Controls.RemoveAt(...);

Once the controls in the Controls-collection are gone, the Event that
redraws your tableLayoutPanel doesn't draw them again.

Hopes this is working for you as well...

"avanti" wrote:
Hi,

I am trying to delete rows from a TableLayoutPanel at Runtime. I tried
editing the RowStyles collection but doesn't do what I want it to. I
have a table with 10 rows. I want to delete rows 2 to 10 at runtime,
keeping the first row unchanged.

Can this be done?

Thanks,
Avanti Ketkar

Aug 7 '06 #2
Ok the problem seems to be a little bit more complicated than I thought at
first sight.

Solution, what to do when removing a row:
- decrement tableLayoutPanel.RowCount
- remove rowstyle: tableLayoutPanel.RowStyles.RemoveAt(...)
- remove corresponding controls of removed row in tabelLayoutPanel.Controls
- change RowCounter of controls that come after the removed row

Explanation of last action:
tableLayout.GetRow('control'), where 'control' is a control belonging to a
row that comes after the remove row, will give you his old rowIndex!
For that you need to set the new rowIndex for all controls belonging to a
row that's coming after a removed row.

My code:
for (int counter = controlsCounter; counter <
ux_tlpCostCenters.Controls.Count; counter++)
{
ux_tlpCostCenters.SetRow(ux_tlpCostCenters.Control s[counter],
ux_tlpCostCenters.GetRow(ux_tlpCostCenters.Control s[counter]) - 1);
}

Over here the integer 'controlsCounter' is the beginindex of the first
control in my tableLayoutPanel.Controls that needs a new RowIndex.

This should really help now ;-)

"avanti" wrote:
Hi,

I am trying to delete rows from a TableLayoutPanel at Runtime. I tried
editing the RowStyles collection but doesn't do what I want it to. I
have a table with 10 rows. I want to delete rows 2 to 10 at runtime,
keeping the first row unchanged.

Can this be done?

Thanks,
Avanti Ketkar

Aug 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: 1qa2ws | last post by:
Hi, Where can I find a control for VS .NET 2003 (C#) which works like TableLayoutPanel in VS 2005? What I need? I need a table view where in each cell I can put whatever I want (button, label,...
2
by: Sudha Pune | last post by:
Hi all i am using vs2005 C# window application i am trying to add the controls dynamically inside the "tablelayoutpanel", i need to add row by row and each row i will have to have 10 columns...
0
by: Sudha Chennai | last post by:
I am using windows forms control TableLayoutPanel and C#, VS2005 I want to remove/delete the rows dynamically from TableLayoutPanel... i dont find any links guiding me this.... can u anyone...
2
by: steve | last post by:
Hi All I need to change the rowspan, columnspan properties of a control when they are within a TableLayoutPanel (VB.net 2005) At runtime the property is not available, but is at design time ...
3
by: swartzbill2000 | last post by:
Hello, I have an array of Buttons down a column of a TableLayoutPanel. They all share a common click handler. In the handler, how can I determine the row of the TableLayoutPanel for the Button...
0
by: Desperate | last post by:
How how i determine all the TableLayoutPanel in me. is it any diffferent if the TableLayoutPanel are within containers?
0
by: strattonn | last post by:
I have a TableLayoutPanel on a form and I would like to freeze the first row and column so they do not scroll off the screen. Just like Excel's Fixed Row/Column feature. I have a feeling the...
4
by: Jeff | last post by:
Hello, I am trying to drag and drop a label control from one cell in a tablelayoutpanel to another (VB2005). There is no problem if both cells are visible, but i cannot get the tablelayoutpanel...
0
by: yoav.sagi | last post by:
hi, i am Inheriting from TableLayoutPane with a designer that inherits from ParentControlDesigner ..i would like to allow the user to resize the columns and rows ..All rows and columns SizeType =...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.