I have TableLayoutPanel set on a Panel and I have AutoScroll set to True for both these.
The TableLayoutPanel is made of only 1 row and 1 column at design time. At run time I am adding a chart to new row (starting at row index 1), with no columns added. The chart is docked into the row cell.
However, I don't see vertical scrollbar to scroll the charts. Initially, I didn't had the Panel, since TableLayoutPanel wasn't showing any scrollbar I added Panel, but of no use.
Can you please test the attached code and suggest fix?
Form1.Designer.cs
namespace WinFormApp { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.panel1 = new System.Windows.Forms.Panel(); this.button1 = new System.Windows.Forms.Button(); this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); this.panel1.SuspendLayout(); this.SuspendLayout(); // // panel1 // this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.panel1.AutoScroll = true; this.panel1.BackColor = System.Drawing.Color.Blue; this.panel1.Controls.Add(this.tableLayoutPanel1); this.panel1.Location = new System.Drawing.Point(2, 70); this.panel1.Name = "panel1"; this.panel1.Size = new System.Drawing.Size(280, 190); this.panel1.TabIndex = 0; // // button1 // this.button1.Location = new System.Drawing.Point(13, 13); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // tableLayoutPanel1 // this.tableLayoutPanel1.AutoScroll = true; this.tableLayoutPanel1.BackColor = System.Drawing.Color.Yellow; this.tableLayoutPanel1.ColumnCount = 1; this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); this.tableLayoutPanel1.Name = "tableLayoutPanel1"; this.tableLayoutPanel1.RowCount = 1; this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); this.tableLayoutPanel1.Size = new System.Drawing.Size(280, 190); this.tableLayoutPanel1.TabIndex = 0; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(282, 255); this.Controls.Add(this.button1); this.Controls.Add(this.panel1); this.Name = "Form1"; this.Text = "Form1"; this.panel1.ResumeLayout(false); this.ResumeLayout(false); } #endregion private System.Windows.Forms.Panel panel1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Button button1; } }
Form1.cs
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; namespace WinFormApp { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("INP",typeof(System.Int16))); dt.Columns.Add(new DataColumn("OUT", typeof(System.Int16))); dt.Rows.Add(1, 2); dt.Rows.Add(3, 5); dt.Rows.Add(6, 20); dt.Rows.Add(3, 9); AddCharts(dt); } private void AddCharts(DataTable dt) { for (int i = 0; i < 10; i++) { // Create Chart Chart chart = new Chart(); ChartArea ca = new ChartArea(); chart.ChartAreas.Add(ca); chart.Legends.Add(new Legend("chart" + i.ToString())); chart.DataSource = dt; chart.Series.Add(new Series("series_for_chart_" + i.ToString())); chart.Series[0].IsXValueIndexed = true; chart.Series[0].ChartType = SeriesChartType.Point; chart.Series[0].XValueType = ChartValueType.Int32; chart.Series[0].XValueMember = dt.Columns["INP"].ToString(); chart.Series[0].YValueType = ChartValueType.Int32; chart.Series[0].YValueMembers = dt.Columns["OUT"].ToString(); chart.DataBind(); // Add chart to new row of the tableLayoutPanel tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize)); tableLayoutPanel1.RowCount = tableLayoutPanel1.RowStyles.Count; int currentRow = tableLayoutPanel1.RowCount - 1; tableLayoutPanel1.Controls.Add(chart, currentRow, 0); chart.Dock = DockStyle.Fill; //chart.Anchor = ((System.Windows.Forms.AnchorStyles)(System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)); } } } }
Ideally I would like to use only TableLayoutPanel (without Pane) if possible.
Thanks,
-srinivas y.
sri