简体   繁体   中英

TableLayoutPanel Winforms not showing all information

I have a really strange set of circumstances that I just can't seem to get to work. I will let you know what I have and see If you can put me right. (The below represents the closest I have been able to get to what I want).

The idea is that when a day is selected I show a usercontrol that has a lorry's deliveries for that day. The thing is that the date may be a range. Therefore I have the following setup thus far:

I have a

 TableLayoutPanel (Dock = Fill; 1 column (100percent); 1 Row (Autosize). 

Then each selected has a user control (ucSchedulerDay) this is added as a row to the TableLayoutPanel. So take a single day for example, you would have this:

TableLayoutPanel (Dock = Fill; 1 Column (100%); 1 Row (Autosize).
   - (Row1 Column1) ucSchedulerDay

So the ucSchedulerDay is just a user control that houses a GroupBox (Dock=Fill) and a FlowLayoutPanel (also dock=fill inside the groupbox)

For each lorry I have another usercontrol added to the FlowLayoutPanel (these have a fixed width) so essentially what I have is the following for one single day

TableLayoutPanel (as above (also forgot to mention that AutoScrollBars=True)
  - (Row 1 Column 1) ucSchedulerDay (Dock=Fill(done in code when added))
    - GroupBox (Dock=Fill)
      - FlowLayoutPanel (Dock=Fill)
        - ucLorryDay1
        - ucLorryDay2

工作画面 This works fine as long as all the lorries fit on the screen (see above), so for one day with 2 lorries(or even up to 5 on my monitor) then it's ok. However, if I select two days or make the screen smaller, instead of showing the scroll bars but generally having the same layout, it cuts some of the ucLorryDays up and just doesn't display others.

较小的显示或更多的项目出现问题

Note on the above pic how the grey lorry is cut off, even the scroll bar doesn't extend that far.

I don't understand why this isn't working. I would really appreciate any help on this, please let me know if you need more information.

Ok, So I think that the nested GroupBox/UserControl-GroupBox idea was where it all went wrong. I have fixed this by updating the original form to do the following:

  pnlLorries.Controls.Clear();
  DateTime dt_start = monthView1.SelectionStart;
  DateTime dt_end = monthView1.SelectionEnd;
  int rowCounter = 0;
  for (DateTime dt = dt_start; dt.Date <= dt_end; dt = dt.AddDays(1))
  {
    Label lbl = new Label();
    Font ft = new System.Drawing.Font("Calibri", 12);
    lbl.Text = dt.ToShortDateString();
    lbl.Font = ft;
    pnlLorries.Controls.Add(lbl, 0, rowCounter);
    rowCounter++;
    FlowLayoutPanel pnl = new FlowLayoutPanel();
    pnl.Dock = DockStyle.Fill;
    pnl.AutoSize = true;
    DataTable tbl = cDALSettings.DB.GetCannedTable("select * from lorry");
    // Now we simply add these controls to the panel...
    foreach (DataRow row in tbl.Rows)
    {
      ucLorryDay ld = new ucLorryDay(dt, cTypes.ToInt(row["id"]), this);
      pnl.Controls.Add(ld);
    }
    pnlLorries.Controls.Add(pnl, 0, rowCounter);
    rowCounter++;
  }

So I create it all and add in the label. The downside is of course that it is not in a neat little box but even when I did it this way with a groupbox it came back with the same results I was experiencing before. I suppose the problem was the panel inside a panel (inception style).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM