Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Controls / March 2006

Tip: Looking for answers? Try searching our database.

TableLayoutControl: Adding control to new row

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Barry - 27 Mar 2006 19:39 GMT
I have a TableLayoutControl with 3 columns. At runtime, controls are added one
at a time; they usually need to go into the next available cell, but sometimes
must begin a new row.

I've tried using Controls.Add(item, 0, -1), but this is having the same effect
as Controls.Add(item). In fact, I cannot find any situation where specifying -1
for just the row or column is any different from not specifying either.
Specifying an absolute position is not an option, because my code is relying on
TableLayoutControl adding rows as needed.

Decompiling gives
public virtual void Add(Control control, int column, int row)
{
      base.Add(control);
      this._container.SetColumn(control, column);
      this._container.SetRow(control, row);
}
Andrej Tozon - 28 Mar 2006 17:09 GMT
I'm not sure what exactly you're trying to do, but maybe FlowLayoutPanel
might solve your problem? It allows you to fill the panel with any controls,
from left to right, with optional wrapping. You can also set "breaker
controls", which cause a manual line break.

Hope this helps a bit,
   Andrej

>I have a TableLayoutControl with 3 columns. At runtime, controls are added
>one at a time; they usually need to go into the next available cell, but
[quoted text clipped - 13 lines]
>       this._container.SetRow(control, row);
> }
Barry - 28 Mar 2006 20:16 GMT
> I'm not sure what exactly you're trying to do, but maybe FlowLayoutPanel
> might solve your problem? It allows you to fill the panel with any controls,
> from left to right, with optional wrapping. You can also set "breaker
> controls", which cause a manual line break.
>
> Hope this helps a bit,

Unfortunately it doesn't, I need a grid layout.

By way of example,

align(Control[][] controls, TableLayoutPanel grid) {
    foreach(Control[] row in controls)
        foreach(Control control in row)
            grid.Controls.Add(control);
}

The problem is that each row must begin a new line. To make things easier, the
TableLayoutPanel already has enough columns to accommodate the longest row, but
starts off with no rows. Unlike my trivial example, the rows are created on the
fly by reading a forward-only stream, so setting the number of rows in the grid
and using absolute positioning is not a solution of first resort.
Andrej Tozon - 01 Apr 2006 00:11 GMT
I created the following example, which adds controls to the grid, based on a
control grid array. Run it on a three-column tablelayoutpanel.

// Initialize sample control array
Control[][] controls = new Control[][]
{
   new Control[] {new Button(), new Button(), new Button() },
   new Control[] {new Button(), new Button() },
   new Control[] {new Button()},
   new Control[] {new Button(), new Button() },
   new Control[] {new Button(), new Button(), new Button() }
};

int y = 0;
foreach(Control[] row in controls)
{
   int x = 0;
   foreach (Control control in row)
   {
       // Create control and add it to grid
       grid.Controls.Add(control, x, y);
       if (y < grid.RowCount)
       {
           grid.RowCount++;
       }
       x++;
   }
   y++;
}

Andrej

>> I'm not sure what exactly you're trying to do, but maybe FlowLayoutPanel
>> might solve your problem? It allows you to fill the panel with any
[quoted text clipped - 19 lines]
> of rows in the grid and using absolute positioning is not a solution of
> first resort.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.