awykel
asked on
Scroll bars disappear when docked in TabPage
I have a dynamic TabControl that generates the tabPages on the fly, I have a user control that has a split container with a DataGridView displayed in SplitContainer.Panel2. When I dock the user control in the TabPage the scrollbar for the DataGridView disapears. I have used Microsofts Designer surface to try to recreate the problem with no luck. I even mirrirored the auto generated designer.cs code Visual Studio generates. I have tried sizing options, ancoring, nothing seems to get the scrollbars into view.
//generates the TabPage...
public TabPage AddAutoPositionTabPage(String name, String text, int index)
{
TabPage tabPage = new System.Windows.Forms.TabPage();
SplitContainer splitContainer = new System.Windows.Forms.SplitContainer();
System.Windows.Forms.DataGridView dataGridView1 = new DataGridView();
System.Windows.Forms.TableLayoutPanel panel1 = new TableLayoutPanel();
System.Windows.Forms.TableLayoutPanel panel2 = new TableLayoutPanel();
System.Windows.Forms.GroupBox groupBox1 = new GroupBox();
System.Windows.Forms.GroupBox groupBox2 = new GroupBox();
System.Windows.Forms.VScrollBar vScrollBar2 = new VScrollBar();
System.Windows.Forms.VScrollBar vScrollBar1 = new VScrollBar();
tabPage.SuspendLayout();
splitContainer.Panel1.SuspendLayout();
splitContainer.Panel2.SuspendLayout();
splitContainer.SuspendLayout();
groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(dataGridView1)).BeginInit();
groupBox2.SuspendLayout();
panel1.SuspendLayout();
panel2.SuspendLayout();
SuspendLayout();
splitContainer.SuspendLayout();
//
// tabPage.1
//
tabPage.Controls.Add(splitContainer);
tabPage.Location = new System.Drawing.Point(4, 22);
tabPage.Name = name;
tabPage.Padding = new System.Windows.Forms.Padding(3);
tabPage.Size = this.Size;//new System.Drawing.Size(489, 497);
tabPage.TabIndex = 0;
tabPage.Text = text;
tabPage.UseVisualStyleBackColor = true;
//
// splitContainer.1
//
splitContainer.Dock = System.Windows.Forms.DockStyle.Fill;
splitContainer.Location = new System.Drawing.Point(3, 3);
splitContainer.Name = name + "_splitContainer";
splitContainer.Orientation = System.Windows.Forms.Orientation.Horizontal;
splitContainer.Size = this.Size;//new System.Drawing.Size(483, 491);
//
// splitContainer1.Panel1
//
splitContainer.Panel1.Controls.Add(dataGridView1);
splitContainer.Panel1.Controls.Add(groupBox1);
//splitContainer.Panel1.Controls.Add(panel2);
//
// splitContainer1.Panel2
//
splitContainer.Panel2.Controls.Add(groupBox2);
//splitContainer.Panel2.Controls.Add(panel1);
splitContainer.Size = this.Size;// new System.Drawing.Size(483, 491);
splitContainer.SplitterDistance = 256;
splitContainer.TabIndex = 0;
//
// groupBox1
//
groupBox1.Controls.Add(panel2);
groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
groupBox1.Location = new System.Drawing.Point(0, 0);
groupBox1.Name = name + "_groupBox1";
groupBox1.Dock = DockStyle.Top;
groupBox1.Size = new System.Drawing.Size(this.Width, 117);
groupBox1.AutoSize = true;
groupBox1.AutoSizeMode = AutoSizeMode.GrowOnly;
groupBox1.TabIndex = 0;
groupBox1.TabStop = false;
groupBox1.Text = "Filter Section";
//
// dataGridView1
//
dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Dock = System.Windows.Forms.DockStyle.Bottom;
dataGridView1.Dock = DockStyle.Bottom;
dataGridView1.Location = new System.Drawing.Point(0, 123);
dataGridView1.Name = name + "_dataGridView1";
dataGridView1.Size = new System.Drawing.Size(this.Width, 138);
dataGridView1.TabIndex = 1;
//
// groupBox2
//
groupBox2.Controls.Add(panel1);
groupBox2.Dock = DockStyle.Fill;
groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
groupBox2.Location = new System.Drawing.Point(0, 0);
groupBox2.Name = name + "_groupBox2";
groupBox2.Size = new System.Drawing.Size(this.Width, 226);
groupBox2.AutoSize = true;
groupBox2.AutoSizeMode = AutoSizeMode.GrowOnly;
groupBox2.TabIndex = 0;
groupBox2.TabStop = false;
groupBox2.Text = "Detail View";
//
// panel1
//
panel1.AutoScroll = true;
panel1.Dock = System.Windows.Forms.DockStyle.Fill;
panel1.Dock = DockStyle.Fill;
panel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, this.Width));
//panel1.FlowDirection = FlowDirection.TopDown;
panel1.Location = new System.Drawing.Point(3, 16);
panel1.Name = name + "_panel1";
panel1.Size = new System.Drawing.Size(this.Width, 207);
panel1.MinimumSize = new System.Drawing.Size(477, 207);
panel1.AutoSize = true;
panel1.AutoSizeMode = AutoSizeMode.GrowOnly;
panel1.TabIndex = 0;
//
// panel2
//
panel2.AutoScroll = true;
panel2.Dock = System.Windows.Forms.DockStyle.Fill;
panel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, this.Width));
//panel1.FlowDirection = FlowDirection.TopDown;
panel1.Dock = DockStyle.Fill;
panel2.Location = new System.Drawing.Point(3, 16);
panel2.Name = name + "_panel2";
panel2.Size = new System.Drawing.Size(this.Width, 98);
panel2.MinimumSize = new System.Drawing.Size(477, 98);
panel2.AutoSize = true;
panel2.AutoSizeMode = AutoSizeMode.GrowOnly;
panel2.TabIndex = 0;
AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
if(index == -1)
tabControl1.TabPages.Add(tabPage);
else
tabControl1.TabPages.Insert(index, tabPage);
tabPage.ResumeLayout(false);
splitContainer.Panel1.ResumeLayout(false);
splitContainer.Panel2.ResumeLayout(false);
splitContainer.ResumeLayout(false);
groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(dataGridView1)).EndInit();
groupBox2.ResumeLayout(false);
panel1.ResumeLayout(false);
panel2.ResumeLayout(false);
ResumeLayout(false);
tabPage.Select();
return tabPage;
}
//Adds custom Tab
private void addCustomTab(String tabName, XElement xCustom)
{
TabPage tp = new TabPage();
this.SuspendLayout();
tabControl1.TabPages.Add(tp);
Control c = Generator.CreateUserControl(xCustom);
tp.Controls.Add(c);
tp.Location = new System.Drawing.Point(4, 22);
tp.Padding = new System.Windows.Forms.Padding(3);
tp.Size = new System.Drawing.Size(740, 597);
tp.Name = tabName;
tp.Text = tabName;
tp.UseVisualStyleBackColor = true;
c.Dock = DockStyle.Fill;
c.Location = new System.Drawing.Point(3, 3);
c.Size = new System.Drawing.Size(734, 591);
c.TabIndex = 0;
this.ResumeLayout();
}
Which scrollbar disappears? The horizontal or the vertical one? Have you tried making the DataGridView so that it is docked to fill the panel?
ASKER
The horozontal scroll bar at the bottom of the screen. Yes I beleive everything is docked properly.
Outline on docking and anchoring:
Split container = Dock.Fill / (anchor Top,Left)
UserControl = Dock.Fill / (Anchor: None)
SplitContainer.Panel2 DataGridView = Dock.Fill / (anchor Top,Left)
SplitContainer.Panel1 Panel1 = Dock.Fill / (anchor Top,Left)
Outline on docking and anchoring:
Split container = Dock.Fill / (anchor Top,Left)
UserControl = Dock.Fill / (Anchor: None)
SplitContainer.Panel2 DataGridView = Dock.Fill / (anchor Top,Left)
SplitContainer.Panel1 Panel1 = Dock.Fill / (anchor Top,Left)
ASKER
Okay I just learned this is a docking problem. Perhaps I don't understand Microsoft .NET docking.
Seems the root of the problem is another user control where the TabControl is Dock.Fill and at the bottom there is aa button bar that is Dock.Bottom.
the problem is that the size of the TabControl = the Size of the UserControl
So the buttonBar is blocking the scrollBar.
I need help with Docking basics I guess. Somethings in .NET seem intutive but turn out to scorn you in the end, does any one have any remedies?
Seems the root of the problem is another user control where the TabControl is Dock.Fill and at the bottom there is aa button bar that is Dock.Bottom.
the problem is that the size of the TabControl = the Size of the UserControl
So the buttonBar is blocking the scrollBar.
I need help with Docking basics I guess. Somethings in .NET seem intutive but turn out to scorn you in the end, does any one have any remedies?
I wrote this article on docking - perhaps it will help you:
http://articles.techrepublic.com.com/5100-3513-6165908.html
http://articles.techrepublic.com.com/5100-3513-6165908.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.