Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17840


Ignore:
Timestamp:
02/17/21 23:03:51 (4 years ago)
Author:
mkommend
Message:

#3104: Fixed copying of values from a StringConvertibleMatrixView.

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

Legend:

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

    r17180 r17840  
    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);
  • trunk/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r17180 r17840  
    306306    private void CopyValuesFromDataGridView() {
    307307      if (dataGridView.SelectedCells.Count == 0) return;
     308
     309      //if not all cells are selected use the built-in functionality for copying values to the clipboard
     310      if (!dataGridView.AreAllCellsSelected(false)) {
     311        dataGridView.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
     312        var data = dataGridView.GetClipboardContent();
     313        Clipboard.SetDataObject(data);
     314        return;
     315      }
     316
     317      //Ff all cells are selected we want to include row and column headers if they are set in the content.
     318      //This is not possible with the built-in functionality, because only both headers can be added.
     319      //Furthermore, the current implementation of the view with the virtual datagridview does set
     320      //rowheaders only when they are displayed (see UpdateRowHeaders) and otherwise leaves them empty.
     321
    308322      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
     323
     324      bool addColumnNames = Content.ColumnNames.Any();
     325      bool addRowNames = Content.RowNames.Any();
     326
     327      //add first row with column headers
    329328      if (addColumnNames) {
    330         if (addRowNames)
    331           s.Append('\t');
    332 
     329        var columnNames = Content.ColumnNames.ToArray();
     330        if (addRowNames) s.Append('\t'); //there is no column header for the row headers
    333331        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
    334332        while (column != null) {
    335           s.Append(column.HeaderText);
     333          s.Append(columnNames[column.Index]);
    336334          s.Append('\t');
     335
    337336          column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
    338337        }
     338        s.Append(Environment.NewLine);
     339      }
     340
     341      var rowNames = Content.RowNames.ToArray();
     342      for (int r = 0; r < dataGridView.RowCount; r++) {
     343        if (!dataGridView.Rows[r].Visible) continue; //skip invisible rows
     344
     345        int rowIndex = virtualRowIndices[r];
     346        if (addRowNames) {
     347          s.Append(rowNames[rowIndex]);
     348          s.Append('\t');
     349        }
     350
     351        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
     352        while (column != null) {
     353          s.Append(Content.GetValue(rowIndex, column.Index));
     354          s.Append('\t');
     355
     356          column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None);
     357        }
     358
    339359        s.Remove(s.Length - 1, 1); //remove last tab
    340360        s.Append(Environment.NewLine);
    341361      }
    342362
    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       }
    365363      Clipboard.SetText(s.ToString());
    366364    }
Note: See TracChangeset for help on using the changeset viewer.