Changeset 17840
- Timestamp:
- 02/17/21 23:03:51 (4 years ago)
- 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 71 71 // rowsTextBox 72 72 // 73 this.rowsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 74 73 this.rowsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 74 | System.Windows.Forms.AnchorStyles.Right))); 75 75 this.rowsTextBox.Location = new System.Drawing.Point(69, 0); 76 76 this.rowsTextBox.Name = "rowsTextBox"; … … 86 86 this.dataGridView.AllowUserToDeleteRows = false; 87 87 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 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; 92 92 this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.DisableResizing; 93 93 this.dataGridView.Location = new System.Drawing.Point(0, 52); … … 115 115 // columnsTextBox 116 116 // 117 this.columnsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 118 117 this.columnsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 118 | System.Windows.Forms.AnchorStyles.Right))); 119 119 this.columnsTextBox.Location = new System.Drawing.Point(69, 26); 120 120 this.columnsTextBox.Name = "columnsTextBox"; … … 136 136 // contextMenu 137 137 // 138 this.contextMenu.ImageScalingSize = new System.Drawing.Size(20, 20); 138 139 this.contextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 139 140 this.ShowHideColumns}); … … 150 151 // statisticsTextBox 151 152 // 152 this.statisticsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 153 153 this.statisticsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 154 | System.Windows.Forms.AnchorStyles.Right))); 154 155 this.statisticsTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None; 155 156 this.statisticsTextBox.Location = new System.Drawing.Point(3, 388); … … 161 162 // StringConvertibleMatrixView 162 163 // 163 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);164 164 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 165 165 this.Controls.Add(this.columnsTextBox); -
trunk/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs
r17180 r17840 306 306 private void CopyValuesFromDataGridView() { 307 307 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 308 322 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 329 328 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 333 331 DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible); 334 332 while (column != null) { 335 s.Append(column .HeaderText);333 s.Append(columnNames[column.Index]); 336 334 s.Append('\t'); 335 337 336 column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None); 338 337 } 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 339 359 s.Remove(s.Length - 1, 1); //remove last tab 340 360 s.Append(Environment.NewLine); 341 361 } 342 362 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 tab363 s.Append(Environment.NewLine);364 }365 363 Clipboard.SetText(s.ToString()); 366 364 }
Note: See TracChangeset
for help on using the changeset viewer.