1

I'm trying to build a table that is autoscrollable and I took inspiration from this example: Add Row Dynamically in TableLayoutPanel.

I already set on autoscroll true and I created only 3 static columns for my case but autoscroll doesn't work.

Example of my code:

        panel.ColumnCount = 0;
        panel.RowCount = 0;

        panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
        panel.Controls.Add(new Label() { Text = "           Address" }, 0, 0);
        panel.Controls.Add(new Label() { Text = "           Contact No" }, 1, 0);
        panel.Controls.Add(new Label() { Text = "           Email ID" }, 2, 0);



        for (int i = 0; i <= 8; i++)
        {
            // For Add New Row (Loop this code for add multiple rows)
            panel.RowCount = panel.RowCount + 1;
            panel.RowStyles.Add(new RowStyle(SizeType.Absolute, 50F));
            panel.Controls.Add(new Label() { Text = "Street, City, State" }, 0, panel.RowCount - 1);
            panel.Controls.Add(new Label() { Text = "888888888888" }, 1, panel.RowCount - 1);
            panel.Controls.Add(new Label() { Text = "xxxxxxx@gmail.com" }, 2, panel.RowCount - 1);
        }

        panel.AutoScroll = true;

Table

Properties

T.S.
  • 18,195
  • 11
  • 58
  • 78
Programmer
  • 103
  • 1
  • 9
  • Auto scroll will work if there is rows out of size of the table I think, so the scroll bar will be shown if you added more rows !! – Kaj Jun 08 '18 at 19:48
  • Forgot to mention, try with AutoSize = true; also !! – Kaj Jun 08 '18 at 19:56
  • there are many other rows before latests which you can see in the screenshot... Only 4 rows are shown and others not. – Programmer Jun 08 '18 at 19:59
  • Did u tried with AutoSize = true; ? – Kaj Jun 08 '18 at 20:03
  • on the contrary with autosize = true , former rows are shown and latests not but table is not autoscrollable yet. – Programmer Jun 08 '18 at 20:04
  • Ok I got it. If you dock the table, with autoSize = true; you will get the scroll bar. – Kaj Jun 08 '18 at 20:08
  • i setted dock mode: fill ... table is sized automatically to the panel where it is , but nothing changes apart the size... autoscroll still doesn't work and it's still a nightmare – Programmer Jun 08 '18 at 20:13
  • That's weird. I docked mine to right to the form and I got both scroll bars, vertical and horizontal ! – Kaj Jun 08 '18 at 20:14
  • my table is contained in another forms.panel as i said... This is the screenshot about what happens setting these options suggested by you https://i.imgur.com/u2qJSej.png – Programmer Jun 08 '18 at 20:19
  • Ok here's what I did, I added a panel to my form, then added a tablelayout docked fill to panel, I got both scroll bars ! even if i dock the panel to form, I got both scroll bars ! Here is a photo : https://imgur.com/izQHDH4 another photo with panel docked to form : https://imgur.com/MQGmwxy – Kaj Jun 08 '18 at 20:26
  • i created another form and i filled it to the entire form but it still doesn't work: https://i.imgur.com/uysq3la.png https://i.imgur.com/Y8FV3jL.png https://i.imgur.com/GSrHoZc.png – Programmer Jun 08 '18 at 20:32
  • if you dock table to fill the whole form, it doesn't work. You have to dock it to one side ( I tried with right ), or add a panel, then add the table to fill the panel. Both worked for me ! but if you add a table to form and dock to fill, it doesn't work ! – Kaj Jun 08 '18 at 20:34
  • right or left or filled, it doesn't work.... check out pic of post above – Programmer Jun 08 '18 at 20:37
  • I used ur exact code with the settings I posted and it works as I showed in pictures ! Here is the settings from VS : https://imgur.com/6FuFmNC table docked to panel and filled ! nothing wrong, scroll bars shown ! – Kaj Jun 08 '18 at 20:40
  • I solved! i setted these options: https://i.imgur.com/dna0Ady.png i have now to set only the exact width because not the entire informations that i want are shown – Programmer Jun 08 '18 at 20:45
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/172787/discussion-between-programmer-and-kaj). – Programmer Jun 08 '18 at 20:58
  • Using TLP to implement a grid control is a very drastic mistake. You've got DataGridView in the toolbox, there are many alternatives out there. – Hans Passant Jun 09 '18 at 12:11

1 Answers1

1

I solved it! I have set these options:

Thanks to kaj for helping me!

Striezel
  • 3,693
  • 7
  • 23
  • 37
Programmer
  • 103
  • 1
  • 9