Results 1 to 6 of 6

Thread: [Solved] RowSpan on a table created dynamically located inside another table

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Location
    Houston, TX
    Posts
    7

    [Solved] RowSpan on a table created dynamically located inside another table

    I'm writing a scheduling program that queries a MySQL database for today's appointments and uses a Table Layout Panel with employees on the top and times on the left to display the schedule. I am trying to add another table ontop of that table for each appointment and set the rowspan of that dynamic table to occupy the time slot of that appointment from start to finish.

    All the appointments appear in the dynamic table and each dynamic table appears in the appropriate starting positions in the main table. When you are designing GUI's and put a Table within a table, you get a RowSpan and ColumnSpan option for that inner table. The problem I'm having is the dynamic tables are not giving me a RowSpan option, which I believe is because it was created using code and doesn't know that it's inside another table.

    Here is part of the code... This code is inside loops for each appointment of each employee

    sqlCustomer = MyReader.GetValue(0).ToString()
    sqlCompany = MyReader.GetValue(1).ToString()
    sqlProblem = MyReader.GetValue(2).ToString()
    sqlStart = MyReader.GetValue(3).ToString()
    sqlEnd = MyReader.GetValue(4).ToString()

    'Create new label
    Dim lblAppointment As New Label
    lblAppointment.Name = aryEmployees(i) & sqlStart
    If sqlCompany = "" Then
    lblAppointment.Text = sqlCustomer
    Else
    lblAppointment.Text = sqlCompany
    End If

    'Create new table
    Dim tblAppointment As New TableLayoutPanel
    tblAppointment.ColumnCount = 1
    tblAppointment.RowCount = 1
    tblAppointment.Dock = DockStyle.Fill
    tblAppointment.Controls.Add(lblAppointment, 0, 0)

    'Find start and end rows
    For Each Label In tblSchedule.Controls
    If Label.Text = sqlStart Then
    intStart = tblSchedule.GetRow(Label)
    End If
    If Label.Text = sqlEnd Then
    intEnd = tblSchedule.GetRow(Label)
    End If
    Next

    'Add label to schedule
    tblSchedule.Controls.Add(tblAppointment, i, intStart)

    'Span table to fill time slot
    tblAppointment.RowSpan = intEnd - intStart

    The very last line gives me an error saying that "RowSpan is not a member of 'System.Windows.Forms.TableLayoutPanel'." Is there a workaround/fix or alternate way of doing this that you can think of? I would like to avoid using Data Grids.
    Last edited by Jaysen; Apr 27th, 2009 at 01:01 PM. Reason: Problem Solved

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: RowSpan on a table created dynamically located inside another table

    The way to resize a TLP's rows is like this:

    Code:
    mytlp.RowStyles.Item(0).SizeType = SizeType.Absolute
    mytlp.RowStyles.Item(0).Height = 50 'Pixels Method  1
    
    mytlp.RowStyles.Item(0).SizeType = SizeType.Percent
    mytlp.RowStyles.Item(0).Height = 50 'Percent Method 2
    
    mytlp.RowStyles.Item(0).SizeType = SizeType.AutoSize 'Auto Method 3

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Location
    Houston, TX
    Posts
    7

    Re: RowSpan on a table created dynamically located inside another table

    I appreciate the quick response, but maybe I didn't make my problem clear. I have a table layout panel named tblSchedule that has time labels on the left and employees along the top. When the form loads, it connects to a MySQL database and grabs all appointments for the listed employees and adds them to tblSchedule.

    Sizing is not a issue, I have the form laid out as I want it. The problem is the appointment currently only occupies one cell of tblSchedule, where I need it to span across multiple rows of tblSchedule. I have tried adding the appointment (which is a label) to a table (named tblAppointment) created using code, then spanning that table ontop of tblShedule, but it doesn't recognize that the tblAppointment is ontop of tblSchedule, so I don't get the RowSpan that I need in order to make this work. That's the issue I'm having.
    "If you are ever challenged with a difficult task, reassign it to a lazy man. He will find an easier way to do it."

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Location
    Houston, TX
    Posts
    7

    Re: RowSpan on a table created dynamically located inside another table

    Does nobody know of a better way to do this, or what I'm doing wrong?
    "If you are ever challenged with a difficult task, reassign it to a lazy man. He will find an easier way to do it."

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: RowSpan on a table created dynamically located inside another table

    As the error message says, RowSpan isn't a member of any control. It's just made to look that way in the designer for convenience. Try this:

    1. Create a new project.
    2. Add a TLP to your form.
    3. Add a Button to your TLP.
    4. Set the Button's RowSpan and ColumnSpan both to 2.
    5. Open the Solution Explorer and click the Show All Files button.
    6. Expand the node for your form and double-click on the designer.vb file.
    7. Observe the code that is generated to set the row span and column span.

    You need to mimic that code. This is always the best way to work out how to do things in code that you would usually do in the designer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6

    Thread Starter
    New Member
    Join Date
    Sep 2008
    Location
    Houston, TX
    Posts
    7

    Re: [Solved] RowSpan on a table created dynamically located inside another table

    Thank you very much! Issue is solved, pasted the code below for anyone else with the same issue.

    Code:
    Table.SetRowSpan(Control, Number Of Rows)
    "If you are ever challenged with a difficult task, reassign it to a lazy man. He will find an easier way to do it."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width