Changeset 7318
- Timestamp:
- 01/11/12 17:44:26 (13 years ago)
- 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 71 71 this.lengthTextBox.Size = new System.Drawing.Size(372, 20); 72 72 this.lengthTextBox.TabIndex = 1; 73 this.lengthTextBox.Validated += new System.EventHandler(this.lengthTextBox_Validated);74 73 this.lengthTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.lengthTextBox_KeyDown); 75 74 this.lengthTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.lengthTextBox_Validating); 75 this.lengthTextBox.Validated += new System.EventHandler(this.lengthTextBox_Validated); 76 76 // 77 77 // dataGridView … … 89 89 this.dataGridView.Size = new System.Drawing.Size(424, 378); 90 90 this.dataGridView.TabIndex = 2; 91 this.dataGridView.CellEndEdit += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView_CellEndEdit); 91 92 this.dataGridView.CellParsing += new System.Windows.Forms.DataGridViewCellParsingEventHandler(this.dataGridView_CellParsing); 92 93 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); 94 95 // 95 96 // errorProvider -
trunk/sources/HeuristicLab.Data.Views/3.3/StringConvertibleArrayView.cs
r7259 r7318 23 23 using System.ComponentModel; 24 24 using System.Drawing; 25 using System.Text; 25 26 using System.Windows.Forms; 26 27 using HeuristicLab.Common; … … 153 154 dataGridView.Rows[e.RowIndex].ErrorText = string.Empty; 154 155 } 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 } 155 200 #endregion 156 201 }
Note: See TracChangeset
for help on using the changeset viewer.