- Timestamp:
- 01/11/12 17:44:26 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.