Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7318 for trunk


Ignore:
Timestamp:
01/11/12 17:44:26 (13 years ago)
Author:
abeham
Message:

#1754: Added copy & paste support for StringConvertibleArrayView similar to StringConvertibleMatrixView

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

Legend:

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

    r7259 r7318  
    7171      this.lengthTextBox.Size = new System.Drawing.Size(372, 20);
    7272      this.lengthTextBox.TabIndex = 1;
    73       this.lengthTextBox.Validated += new System.EventHandler(this.lengthTextBox_Validated);
    7473      this.lengthTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lengthTextBox_KeyDown);
    7574      this.lengthTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.lengthTextBox_Validating);
     75      this.lengthTextBox.Validated += new System.EventHandler(this.lengthTextBox_Validated);
    7676      //
    7777      // dataGridView
     
    8989      this.dataGridView.Size = new System.Drawing.Size(424, 378);
    9090      this.dataGridView.TabIndex = 2;
     91      this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
    9192      this.dataGridView.CellParsing += new System.Windows.Forms.DataGridViewCellParsingEventHandler(this.dataGridView_CellParsing);
    9293      this.dataGridView.CellValidating += new System.Windows.Forms.DataGridViewCellValidatingEventHandler(this.dataGridView_CellValidating);
    93       this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit);
     94      this.dataGridView.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView_KeyDown);
    9495      //
    9596      // errorProvider
  • trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs

    r7259 r7318  
    2323using System.ComponentModel;
    2424using System.Drawing;
     25using System.Text;
    2526using System.Windows.Forms;
    2627using HeuristicLab.Common;
     
    153154      dataGridView.Rows[e.RowIndex].ErrorText = string.Empty;
    154155    }
     156    private void dataGridView_KeyDown(object sender, KeyEventArgs e) {
     157      if (!ReadOnly && e.Control && e.KeyCode == Keys.V)
     158        PasteValuesToDataGridView();
     159      else if (e.Control && e.KeyCode == Keys.C)
     160        CopyValuesFromDataGridView();
     161      else if (e.Control && e.KeyCode == Keys.A)
     162        dataGridView.SelectAll();
     163    }
     164    private void CopyValuesFromDataGridView() {
     165      if (dataGridView.SelectedCells.Count == 0) return;
     166      StringBuilder s = new StringBuilder();
     167      int minRowIndex = dataGridView.SelectedCells[0].RowIndex;
     168      int maxRowIndex = dataGridView.SelectedCells[dataGridView.SelectedCells.Count - 1].RowIndex;
     169
     170      if (minRowIndex > maxRowIndex) {
     171        int temp = minRowIndex;
     172        minRowIndex = maxRowIndex;
     173        maxRowIndex = temp;
     174      }
     175
     176      for (int i = minRowIndex; i <= maxRowIndex; i++) {
     177        DataGridViewColumn column = dataGridView.Columns.GetFirstColumn(DataGridViewElementStates.Visible);
     178        DataGridViewCell cell = dataGridView[column.Index, i];
     179        if (cell.Selected) {
     180          s.Append(Content.GetValue(i));
     181          s.Append(Environment.NewLine);
     182        }
     183      }
     184      Clipboard.SetText(s.ToString());
     185    }
     186    private void PasteValuesToDataGridView() {
     187      string[] values = SplitClipboardString(Clipboard.GetText());
     188      int rowIndex = 0;
     189      if (dataGridView.CurrentCell != null)
     190        rowIndex = dataGridView.CurrentCell.RowIndex;
     191
     192      if (Content.Length < rowIndex + values.Length) Content.Length = rowIndex + values.Length;
     193      for (int row = 0; row < values.Length; row++)
     194        Content.SetValue(values[row], row + rowIndex);
     195    }
     196    private string[] SplitClipboardString(string clipboardText) {
     197      clipboardText = clipboardText.Remove(clipboardText.Length - Environment.NewLine.Length);  //remove last newline constant
     198      return clipboardText.Split(new string[] { Environment.NewLine, "\t" }, StringSplitOptions.None);
     199    }
    155200    #endregion
    156201  }
Note: See TracChangeset for help on using the changeset viewer.