Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/02/10 15:30:42 (13 years ago)
Author:
mkommend
Message:

Added StatusStrip in StringConvertibleMatrixView to diplay statistical information (ticket #1253).

Location:
trunk/sources/HeuristicLab.Data.Views/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.Designer.cs

    r4477 r4709  
    5454      this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
    5555      this.ShowHideColumns = new System.Windows.Forms.ToolStripMenuItem();
     56      this.statusStrip = new System.Windows.Forms.StatusStrip();
     57      this.toolStripStatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
    5658      ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
    5759      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5860      this.contextMenu.SuspendLayout();
     61      this.statusStrip.SuspendLayout();
    5962      this.SuspendLayout();
    6063      //
     
    9396      this.dataGridView.Name = "dataGridView";
    9497      this.dataGridView.RowHeadersWidth = 160;
    95       this.dataGridView.Size = new System.Drawing.Size(424, 352);
     98      this.dataGridView.Size = new System.Drawing.Size(424, 327);
    9699      this.dataGridView.TabIndex = 4;
    97100      this.dataGridView.VirtualMode = true;
     
    102105      this.dataGridView.ColumnHeaderMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView_ColumnHeaderMouseClick);
    103106      this.dataGridView.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dataGridView_Scroll);
     107      this.dataGridView.SelectionChanged += new System.EventHandler(this.dataGridView_SelectionChanged);
    104108      this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown);
    105       this.dataGridView.MouseClick += new System.Windows.Forms.MouseEventHandler(dataGridView_MouseClick);
     109      this.dataGridView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.dataGridView_MouseClick);
    106110      this.dataGridView.Resize += new System.EventHandler(this.dataGridView_Resize);
    107111      //
     
    146150      this.ShowHideColumns.Click += new System.EventHandler(this.ShowHideColumns_Click);
    147151      //
     152      // statusStrip1
     153      //
     154      this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
     155            this.toolStripStatusLabel});
     156      this.statusStrip.Location = new System.Drawing.Point(0, 382);
     157      this.statusStrip.Name = "statusStrip1";
     158      this.statusStrip.Size = new System.Drawing.Size(424, 22);
     159      this.statusStrip.TabIndex = 5;
     160      this.statusStrip.Text = "statusStrip1";
     161      //
     162      // toolStripStatusLabel
     163      //
     164      this.toolStripStatusLabel.Name = "toolStripStatusLabel";
     165      this.toolStripStatusLabel.Size = new System.Drawing.Size(378, 17);
     166      this.toolStripStatusLabel.Spring = true;
     167      //
    148168      // StringConvertibleMatrixView
    149169      //
    150170      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    151171      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     172      this.Controls.Add(this.statusStrip);
    152173      this.Controls.Add(this.dataGridView);
    153174      this.Controls.Add(this.columnsTextBox);
     
    160181      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    161182      this.contextMenu.ResumeLayout(false);
     183      this.statusStrip.ResumeLayout(false);
     184      this.statusStrip.PerformLayout();
    162185      this.ResumeLayout(false);
    163186      this.PerformLayout();
     
    174197    protected System.Windows.Forms.ToolStripMenuItem ShowHideColumns;
    175198    protected System.Windows.Forms.DataGridView dataGridView;
     199    private System.Windows.Forms.StatusStrip statusStrip;
     200    private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel;
    176201
    177202  }
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r4707 r4709  
    5656      get { return showRowsAndColumnsTextBox; }
    5757      set {
    58         if (value != showRowsAndColumnsTextBox) {
    59           showRowsAndColumnsTextBox = value;
    60           UpdateVisibilityOfTextBoxes();
    61         }
     58        showRowsAndColumnsTextBox = value;
     59        UpdateVisibilityOfTextBoxes();
     60      }
     61    }
     62
     63    private bool showStatisticalInformation;
     64    public bool ShowStatisticalInformation {
     65      get { return showStatisticalInformation; }
     66      set {
     67        showStatisticalInformation = value;
     68        UpdateVisibilityOfStatisticalInformation();
    6269      }
    6370    }
     
    6572    public StringConvertibleMatrixView() {
    6673      InitializeComponent();
    67       showRowsAndColumnsTextBox = true;
     74      ShowRowsAndColumnsTextBox = true;
     75      ShowStatisticalInformation = false;
    6876      errorProvider.SetIconAlignment(rowsTextBox, ErrorIconAlignment.MiddleLeft);
    6977      errorProvider.SetIconPadding(rowsTextBox, 2);
     
    496504      rowsTextBox.Visible = columnsTextBox.Visible = showRowsAndColumnsTextBox;
    497505      rowsLabel.Visible = columnsLabel.Visible = showRowsAndColumnsTextBox;
    498 
     506      UpdateDataGridViewSizeAndLocation();
     507    }
     508
     509    private void UpdateVisibilityOfStatisticalInformation() {
     510      statusStrip.Visible = showStatisticalInformation;
     511      UpdateDataGridViewSizeAndLocation();
     512    }
     513
     514    private void UpdateDataGridViewSizeAndLocation() {
    499515      int headerSize = columnsTextBox.Location.Y + columnsTextBox.Size.Height +
    500         columnsTextBox.Margin.Bottom + dataGridView.Margin.Top;
     516       columnsTextBox.Margin.Bottom + dataGridView.Margin.Top;
    501517
    502518      int offset = showRowsAndColumnsTextBox ? headerSize : 0;
    503519      dataGridView.Location = new Point(0, offset);
    504       dataGridView.Size = new Size(Size.Width, Size.Height - offset);
     520
     521      int statusStripHeight = showStatisticalInformation ? statusStrip.Height : 0;
     522      dataGridView.Size = new Size(Size.Width, Size.Height - offset - statusStripHeight);
     523    }
     524
     525    private void dataGridView_SelectionChanged(object sender, EventArgs e) {
     526      toolStripStatusLabel.Text = string.Empty;
     527      if (dataGridView.SelectedCells.Count > 1) {
     528        List<double> selectedValues = new List<double>();
     529        foreach (DataGridViewCell cell in dataGridView.SelectedCells) {
     530          double value;
     531          if (!double.TryParse(cell.Value.ToString(), out value)) return;
     532          selectedValues.Add(value);
     533        }
     534        if (selectedValues.Count > 1) {
     535          StringBuilder labelText = new StringBuilder();
     536          labelText.Append("Average: " + selectedValues.Average() + "    ");
     537          labelText.Append("StdDev: " + selectedValues.StandardDeviation() + "    ");
     538          labelText.Append("Sum: " + selectedValues.Sum() + "    ");
     539          labelText.Append("Count: " + selectedValues.Count + "    ");
     540          toolStripStatusLabel.Text = labelText.ToString();
     541        }
     542      }
    505543    }
    506544  }
Note: See TracChangeset for help on using the changeset viewer.