Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3643


Ignore:
Timestamp:
05/05/10 17:02:39 (14 years ago)
Author:
mkommend
Message:

added paste support for StringConvertibleMatrixView (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

    r3632 r3643  
    102102      this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView_CellValidating);
    103103      this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
     104      this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown);
    104105      this.dataGridView.Resize += new System.EventHandler(this.dataGridView_Resize);
    105106      //
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleMatrixView.cs

    r3566 r3643  
    107107    private void UpdateData() {
    108108      sortedColumnIndizes.Clear();
    109       Sort();
    110109      rowsTextBox.Text = Content.Rows.ToString();
    111110      rowsTextBox.Enabled = true;
     
    123122        dataGridView.ColumnCount = Content.Columns;
    124123
     124      Sort();
    125125      UpdateRowHeaders();
    126126      UpdateColumnHeaders();
     
    250250    private void dataGridView_Resize(object sender, EventArgs e) {
    251251      UpdateRowHeaders();
     252    }
     253
     254    private void dataGridView_KeyDown(object sender, KeyEventArgs e) {
     255      if (!ReadOnly && e.Control && e.KeyCode == Keys.V) { //shortcut for values paste
     256        string[,] values = SplitClipboardString(Clipboard.GetText());
     257
     258        int rowIndex = 0;
     259        int columnIndex = 0;
     260        if (dataGridView.CurrentCell != null) {
     261          rowIndex = dataGridView.CurrentCell.RowIndex;
     262          columnIndex = dataGridView.CurrentCell.ColumnIndex;
     263        }
     264
     265        for (int row = 0; row < values.GetLength(1); row++) {
     266          if (row + rowIndex >= Content.Rows)
     267            Content.Rows = Content.Rows + 1;
     268          for (int col = 0; col < values.GetLength(0); col++) {
     269            if (col + columnIndex >= Content.Columns)
     270              Content.Columns = Content.Columns + 1;
     271            Content.SetValue(values[col, row], row + rowIndex, col + columnIndex);
     272          }
     273        }
     274
     275        ClearSorting();
     276      }
     277    }
     278
     279    private string[,] SplitClipboardString(string clipboardText) {
     280      clipboardText = clipboardText.Remove(clipboardText.Length - Environment.NewLine.Length);  //remove last newline constant
     281      string[,] values = null;
     282      string[] lines = clipboardText.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
     283      string[] cells;
     284      for (int i = 0; i < lines.Length; i++) {
     285        cells = lines[i].Split('\t');
     286        if (values == null)
     287          values = new string[cells.Length, lines.Length];
     288        for (int j = 0; j < cells.Length; j++)
     289          values[j, i] = string.IsNullOrEmpty(cells[j]) ? string.Empty : cells[j];
     290      }
     291      return values;
    252292    }
    253293
     
    281321        }
    282322      }
     323    }
     324
     325    protected void ClearSorting() {
     326      virtualRowIndizes = Enumerable.Range(0, Content.Rows).ToArray();
     327      sortedColumnIndizes.Clear();
     328      UpdateSortGlyph();
    283329    }
    284330
Note: See TracChangeset for help on using the changeset viewer.