2

I've tabcontrol with 3 pages. Within the tabpages are placed listviews. The listviews can be bigger than the tabpage itself.

I wanna add scrollbars on the tabpages

I tried to solve this with the following source:

  lvwAlbums.Parent = pctlDatabeheer.TabPages[1];
            lvwAlbums.Left = 0;
            lvwAlbums.Top = 0;
            lvwAlbums.Width = pctlDatabeheer.TabPages[1].Width - 35;
            lvwAlbums.Height = 1000;// pctlDatabeheer.TabPages[1].Height;
            lvwAlbums.SmallImageList = iltListView;
            lvwAlbums.FullRowSelect = true;
            lvwAlbums.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top;

 foreach (TabPage _Page in pctlDatabeheer.TabPages)
            {
                _Page.AutoScroll = true;
                _Page.AutoScrollMargin = new System.Drawing.Size(20, 20);
                _Page.AutoScrollMinSize = new System.Drawing.Size(_Page.Width, _Page.Height);
            }

But the scroll are not shown. What do I wrong?

Can anybody help me?

Thank yopu for your help.

4
  • 1
    Why don't you make your list views Scrollable ? Commented Sep 25, 2012 at 12:47
  • How do you do that? With Scrollable = true; I didn't see any difference. Commented Sep 25, 2012 at 12:55
  • lvwAlbums.Parent = pctlDatabeheer.TabPages[1]; lvwAlbums.Left = 0; lvwAlbums.Top = 0; lvwAlbums.Width = pctlDatabeheer.TabPages[1].Width - 35; lvwAlbums.Height = pctlDatabeheer.TabPages[1].Height; lvwAlbums.SmallImageList = iltListView; lvwAlbums.FullRowSelect = true; lvwAlbums.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; Commented Sep 25, 2012 at 13:33
  • 1
    It is the anchoring. Remove your anchoring to the bottom. Please remember to upvote and accept if this helps you. Commented Sep 25, 2012 at 13:44

1 Answer 1

4

I created a new Visual Studio WinForms project. Kept the form designer completely empty and used your code:

public Form1()
{
    InitializeComponent();

    // Make TabControl
    TabControl tabControl1 = new TabControl();
    tabControl1.TabPages.Add(new TabPage());
    tabControl1.TabPages.Add(new TabPage());
    tabControl1.Dock = DockStyle.Fill;
    this.Controls.Add(tabControl1);

    // Make long ListView and add to first tab
    ListView listView1 = new ListView();
    listView1.Location = new Point(0, 0);
    listView1.Height = 1000;
    tabControl1.TabPages[0].Controls.Add(listView1);

    // Your code
    foreach (TabPage _Page in tabControl1.TabPages)
    {
        _Page.AutoScroll = true;
        _Page.AutoScrollMargin = new System.Drawing.Size(20, 20);
        _Page.AutoScrollMinSize = new System.Drawing.Size(_Page.Width, _Page.Height);
    }
}

Works perfectly fine. I suspect you have something else wrong but I can't see that or troubleshoot it without seeing your code.

EDIT: Now that you posted some more code, your issue is with your list box:

lvwAlbums.Parent = pctlDatabeheer.TabPages[1];
lvwAlbums.Left = 0;
lvwAlbums.Top = 0;
lvwAlbums.Width = pctlDatabeheer.TabPages[1].Width - 35;
lvwAlbums.Height = 1000;
lvwAlbums.SmallImageList = iltListView;
lvwAlbums.FullRowSelect = true;
// Here is the issue!
// Do not anchor to the bottom or scrolling won't work
lvwAlbums.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Top; 

Don't anchor the control to the bottom. That is causing you the issue. You cannot anchor to the bottom and then scroll. The other anchors are fine.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. But it is much complexer. I've a panel added as parent for the listview. (For so far). But the TabControl is bigger than the form. Now I'm looking for the reason why?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.