473,397 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 30725
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 =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.