Changeset 3312


Ignore:
Timestamp:
04/12/10 16:16:32 (11 years ago)
Author:
mkommend
Message:

added display of row headers (ticket #968)

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

    r3048 r3312  
    8484                  | System.Windows.Forms.AnchorStyles.Left)
    8585                  | System.Windows.Forms.AnchorStyles.Right)));
     86      this.dataGridView.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.DisplayedCells;
    8687      this.dataGridView.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
    8788      this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
    88       this.dataGridView.ColumnHeadersVisible = false;
    8989      this.dataGridView.Location = new System.Drawing.Point(0, 52);
    9090      this.dataGridView.Name = "dataGridView";
     91      this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
    9192      this.dataGridView.Size = new System.Drawing.Size(424, 352);
    9293      this.dataGridView.TabIndex = 4;
     94      this.dataGridView.VirtualMode = true;
     95      this.dataGridView.Scroll += new System.Windows.Forms.ScrollEventHandler(this.dataGridView_Scroll);
     96      this.dataGridView.CellValueNeeded += new System.Windows.Forms.DataGridViewCellValueEventHandler(this.dataGridView_CellValueNeeded);
    9397      this.dataGridView.CellParsing += new System.Windows.Forms.DataGridViewCellParsingEventHandler(this.dataGridView_CellParsing);
    9498      this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView_CellValidating);
    9599      this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
     100      this.dataGridView.Resize += new System.EventHandler(this.dataGridView_Resize);
    96101      //
    97102      // errorProvider
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r3228 r3312  
    2323using System.ComponentModel;
    2424using System.Drawing;
     25using System.Linq;
    2526using System.Windows.Forms;
    2627using HeuristicLab.Common;
     
    8586      columnsTextBox.Text = Content.Columns.ToString();
    8687      columnsTextBox.Enabled = true;
    87       dataGridView.Rows.Clear();
    88       dataGridView.Columns.Clear();
     88      dataGridView.RowCount = 0;
     89      dataGridView.ColumnCount = 0;
    8990      if ((Content.Rows > 0) && (Content.Columns > 0)) {
    90         for (int i = 0; i < Content.Columns; i++) {
    91           dataGridView.ColumnCount++;
    92           dataGridView.Columns[dataGridView.ColumnCount - 1].FillWeight = float.Epsilon;  // sum of all fill weights must not be larger than 65535
    93         }
    9491        dataGridView.RowCount = Content.Rows;
    95         for (int i = 0; i < Content.Rows; i++) {
    96           for (int j = 0; j < Content.Columns; j++)
    97             dataGridView.Rows[i].Cells[j].Value = Content.GetValue(i, j);
    98         }
    99         for (int i = 0; i < Content.Columns; i++)
    100           dataGridView.Columns[i].Width = dataGridView.Columns[i].GetPreferredWidth(DataGridViewAutoSizeColumnMode.AllCells, true);
     92        dataGridView.ColumnCount = Content.Columns;
     93        UpdateRowHeaders();
     94        UpdateColumnHeaders();
    10195      }
    10296      dataGridView.Enabled = true;
     97    }
     98
     99    private void UpdateColumnHeaders() {
     100      for (int i = 0; i < Content.Columns; i++) {
     101        if (Content.ColumnNames.Count() != 0)
     102          dataGridView.Columns[i].HeaderText = Content.ColumnNames.ElementAt(i);
     103        else
     104          dataGridView.Columns[i].HeaderText = "Column " + i;
     105      }
     106      dataGridView.Invalidate();
     107    }
     108
     109    private void UpdateRowHeaders() {
     110      for (int i = dataGridView.FirstDisplayedScrollingRowIndex; i < dataGridView.FirstDisplayedScrollingRowIndex + dataGridView.DisplayedRowCount(true); i++) {
     111        if (Content.RowNames.Count() != 0)
     112          dataGridView.Rows[i].HeaderCell.Value = Content.RowNames.ElementAt(i);
     113        else
     114          dataGridView.Rows[i].HeaderCell.Value = i.ToString();
     115      }
     116      dataGridView.Invalidate();
    103117    }
    104118
     
    178192      dataGridView.Rows[e.RowIndex].ErrorText = string.Empty;
    179193    }
     194    private void dataGridView_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) {
     195      e.Value = Content.GetValue(e.RowIndex, e.ColumnIndex);
     196    }
     197
     198    private void dataGridView_Scroll(object sender, ScrollEventArgs e) {
     199      UpdateRowHeaders();
     200    }
     201
     202    private void dataGridView_Resize(object sender, EventArgs e) {
     203      UpdateRowHeaders();
     204    }
    180205    #endregion
     206
     207
    181208  }
    182209}
Note: See TracChangeset for help on using the changeset viewer.