Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/13/21 10:55:09 (3 years ago)
Author:
gkronber
Message:

#3087: merged r17784:18004 from trunk to branch to prepare for trunk reintegration (fixed a conflict in CrossValidation.cs)

Location:
branches/3087_Ceres_Integration
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3087_Ceres_Integration

  • branches/3087_Ceres_Integration/HeuristicLab.Data.Views

  • branches/3087_Ceres_Integration/HeuristicLab.Data.Views/3.3

  • branches/3087_Ceres_Integration/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.Designer.cs

    r17180 r18006  
    7171      // rowsTextBox
    7272      //
    73       this.rowsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    74                   | System.Windows.Forms.AnchorStyles.Right)));
     73      this.rowsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     74            | System.Windows.Forms.AnchorStyles.Right)));
    7575      this.rowsTextBox.Location = new System.Drawing.Point(69, 0);
    7676      this.rowsTextBox.Name = "rowsTextBox";
     
    8686      this.dataGridView.AllowUserToDeleteRows = false;
    8787      this.dataGridView.AllowUserToOrderColumns = true;
    88       this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    89                   | System.Windows.Forms.AnchorStyles.Left)
    90                   | System.Windows.Forms.AnchorStyles.Right)));
    91       this.dataGridView.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.Disable;
     88      this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
     89            | System.Windows.Forms.AnchorStyles.Left)
     90            | System.Windows.Forms.AnchorStyles.Right)));
     91      this.dataGridView.ClipboardCopyMode = System.Windows.Forms.DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
    9292      this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
    9393      this.dataGridView.Location = new System.Drawing.Point(0, 52);
     
    115115      // columnsTextBox
    116116      //
    117       this.columnsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    118                   | System.Windows.Forms.AnchorStyles.Right)));
     117      this.columnsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     118            | System.Windows.Forms.AnchorStyles.Right)));
    119119      this.columnsTextBox.Location = new System.Drawing.Point(69, 26);
    120120      this.columnsTextBox.Name = "columnsTextBox";
     
    136136      // contextMenu
    137137      //
     138      this.contextMenu.ImageScalingSize = new System.Drawing.Size(20, 20);
    138139      this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
    139140            this.ShowHideColumns});
     
    150151      // statisticsTextBox
    151152      //
    152       this.statisticsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
    153                   | System.Windows.Forms.AnchorStyles.Right)));
     153      this.statisticsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
     154            | System.Windows.Forms.AnchorStyles.Right)));
    154155      this.statisticsTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
    155156      this.statisticsTextBox.Location = new System.Drawing.Point(3, 388);
     
    161162      // StringConvertibleMatrixView
    162163      //
    163       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    164164      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    165165      this.Controls.Add(this.columnsTextBox);
  • branches/3087_Ceres_Integration/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r17180 r18006  
    298298
    299299    protected virtual void dataGridView_KeyDown(object sender, KeyEventArgs e) {
    300       if (!ReadOnly && e.Control && e.KeyCode == Keys.V)
     300      if (!ReadOnly && e.Control && e.KeyCode == Keys.V) {
    301301        PasteValuesToDataGridView();
    302       else if (e.Control && e.KeyCode == Keys.C)
     302        e.Handled = true;
     303      } else if (e.Control && e.KeyCode == Keys.C) {
    303304        CopyValuesFromDataGridView();
     305        e.Handled = true;
     306      }
    304307    }
    305308
    306309    private void CopyValuesFromDataGridView() {
    307310      if (dataGridView.SelectedCells.Count == 0) return;
     311
     312      //if not all cells are selected use the built-in functionality for copying values to the clipboard
     313      if (!dataGridView.AreAllCellsSelected(false)) {
     314        dataGridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
     315        var data = dataGridView.GetClipboardContent();
     316        Clipboard.SetDataObject(data);
     317        return;
     318      }
     319
     320      //If all cells are selected we want to include row and column headers if they are set in the content.
     321      //This is not possible with the built-in functionality, because only both headers can be added.
     322      //Furthermore, the current implementation of the view with the virtual DataGridView does set
     323      //Row headers only when they are displayed (see UpdateRowHeaders) and otherwise leaves them empty.
     324
    308325      StringBuilder s = new StringBuilder();
    309       int minRowIndex = dataGridView.SelectedCells[0].RowIndex;
    310       int maxRowIndex = dataGridView.SelectedCells[dataGridView.SelectedCells.Count - 1].RowIndex;
    311       int minColIndex = dataGridView.SelectedCells[0].ColumnIndex;
    312       int maxColIndex = dataGridView.SelectedCells[dataGridView.SelectedCells.Count - 1].ColumnIndex;
    313 
    314       if (minRowIndex > maxRowIndex) {
    315         int temp = minRowIndex;
    316         minRowIndex = maxRowIndex;
    317         maxRowIndex = temp;
    318       }
    319       if (minColIndex > maxColIndex) {
    320         int temp = minColIndex;
    321         minColIndex = maxColIndex;
    322         maxColIndex = temp;
    323       }
    324 
    325       bool addRowNames = dataGridView.AreAllCellsSelected(false) && Content.RowNames.Count() > 0;
    326       bool addColumnNames = dataGridView.AreAllCellsSelected(false) && Content.ColumnNames.Count() > 0;
    327 
    328       //add colum names
     326
     327      bool addColumnNames = Content.ColumnNames.Any();
     328      bool addRowNames = Content.RowNames.Any();
     329
     330      //add first row with column headers
    329331      if (addColumnNames) {
    330         if (addRowNames)
    331           s.Append('\t');
    332 
     332        var columnNames = Content.ColumnNames.ToArray();
     333        if (addRowNames) s.Append('\t'); //there is no column header for the row headers
    333334        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
    334335        while (column != null) {
    335           s.Append(column.HeaderText);
     336          s.Append(columnNames[column.Index]);
    336337          s.Append('\t');
     338
    337339          column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
    338340        }
     341        s.Append(Environment.NewLine);
     342      }
     343
     344      var rowNames = Content.RowNames.ToArray();
     345      for (int r = 0; r < dataGridView.RowCount; r++) {
     346        if (!dataGridView.Rows[r].Visible) continue; //skip invisible rows
     347
     348        int rowIndex = virtualRowIndices[r];
     349        if (addRowNames) {
     350          s.Append(rowNames[rowIndex]);
     351          s.Append('\t');
     352        }
     353
     354        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
     355        while (column != null) {
     356          s.Append(Content.GetValue(rowIndex, column.Index));
     357          s.Append('\t');
     358
     359          column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
     360        }
     361
    339362        s.Remove(s.Length - 1, 1); //remove last tab
    340363        s.Append(Environment.NewLine);
    341364      }
    342365
    343       for (int i = minRowIndex; i <= maxRowIndex; i++) {
    344         if (!dataGridView.Rows[i].Visible) continue;
    345 
    346         int rowIndex = this.virtualRowIndices[i];
    347         if (addRowNames) {
    348           s.Append(Content.RowNames.ElementAt(rowIndex));
    349           s.Append('\t');
    350         }
    351 
    352         DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
    353         while (column != null) {
    354           DataGridViewCell cell = dataGridView[column.Index, i];
    355           if (cell.Selected) {
    356             s.Append(Content.GetValue(rowIndex, column.Index));
    357             s.Append('\t');
    358           }
    359 
    360           column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
    361         }
    362         s.Remove(s.Length - 1, 1); //remove last tab
    363         s.Append(Environment.NewLine);
    364       }
    365366      Clipboard.SetText(s.ToString());
    366367    }
Note: See TracChangeset for help on using the changeset viewer.