Changeset 17928 for branches/3026_IntegrationIntoSymSpace/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs
- Timestamp:
- 04/06/21 13:13:32 (3 years ago)
- Location:
- branches/3026_IntegrationIntoSymSpace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3026_IntegrationIntoSymSpace
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Data.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Data.Views (added) merged: 17840-17841,17921
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Data.Views/3.3
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Data.Views/3.3 (added) merged: 17840-17841,17921
- Property svn:mergeinfo changed
-
branches/3026_IntegrationIntoSymSpace/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs
r17180 r17928 298 298 299 299 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) { 301 301 PasteValuesToDataGridView(); 302 else if (e.Control && e.KeyCode == Keys.C) 302 e.Handled = true; 303 } else if (e.Control && e.KeyCode == Keys.C) { 303 304 CopyValuesFromDataGridView(); 305 e.Handled = true; 306 } 304 307 } 305 308 306 309 private void CopyValuesFromDataGridView() { 307 310 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 308 325 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 329 331 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 333 334 DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible); 334 335 while (column != null) { 335 s.Append(column .HeaderText);336 s.Append(columnNames[column.Index]); 336 337 s.Append('\t'); 338 337 339 column = dataGridView.Columns.GetNextColumn(column, DataGridViewElementStates.Visible, DataGridViewElementStates.None); 338 340 } 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 339 362 s.Remove(s.Length - 1, 1); //remove last tab 340 363 s.Append(Environment.NewLine); 341 364 } 342 365 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 366 Clipboard.SetText(s.ToString()); 366 367 }
Note: See TracChangeset
for help on using the changeset viewer.