private void grid_KeyDown(GridVirtual sender, KeyEventArgs e) { if (e.Handled) return; if (sender.Selection.IsEmpty()) return; if (e.KeyCode == Keys.Delete) { sender.ClearValues(sender.Selection.GetSelectionRegion()); e.Handled = true; } }
/// <summary> /// Load the specified range data into a string array. This method use the cell editor to get the value. /// </summary> /// <param name="sourceGrid"></param> /// <param name="sourceRange"></param> /// <param name="startDragPosition">Starting drag position. Used only for calculating drop destination range.</param> /// <param name="cutMode">Cut mode. Can be used to remove the data from the source when pasting it to the destination or immediately.</param> public void LoadData(GridVirtual sourceGrid, Range sourceRange, Position startDragPosition, CutMode cutMode) { mSourceGrid = sourceGrid; mCutMode = cutMode; mStartDragPosition = startDragPosition; mSourceRange = sourceRange; mSourceValues = new string[mSourceRange.RowsCount, mSourceRange.ColumnsCount]; int arrayRow = 0; for (int r = mSourceRange.Start.Row; r <= mSourceRange.End.Row; r++, arrayRow++) { int arrayCol = 0; for (int c = mSourceRange.Start.Column; c <= mSourceRange.End.Column; c++, arrayCol++) { Position posCell = new Position(r, c); Cells.ICellVirtual cell = sourceGrid.GetCell(posCell); CellContext cellContext = new CellContext(sourceGrid, posCell, cell); if (cell != null && cell.Editor != null && cell.Editor.IsStringConversionSupported()) { mSourceValues[arrayRow, arrayCol] = cell.Editor.ValueToString(cell.Model.ValueModel.GetValue(cellContext)); } else if (cell != null) { mSourceValues[arrayRow, arrayCol] = cellContext.DisplayText; } } } //Cut Data if (CutMode == CutMode.CutImmediately && sourceGrid != null) { sourceGrid.ClearValues(new RangeRegion(sourceRange)); //for (int sr = sourceRange.Start.Row; sr <= sourceRange.End.Row; sr++) // for (int sc = sourceRange.Start.Column; sc <= sourceRange.End.Column; sc++) // { // Position pos = new Position(sr, sc); // Cells.ICellVirtual cell = sourceGrid.GetCell(sr, sc); // CellContext cellContext = new CellContext(sourceGrid, pos, cell); // if (cell.Editor != null) // cell.Editor.ClearCell(cellContext); // } } mClipboardDataObject = new System.Windows.Forms.DataObject(); mClipboardDataObject.SetData(RANGEDATA_FORMAT, this); mClipboardDataObject.SetData(typeof(string), DataToString(mSourceValues, mSourceRange)); }
/// <summary> /// Load the specified range data into a string array. This method use the cell editor to get the value. /// </summary> /// <param name="sourceGrid"></param> /// <param name="sourceRange"></param> /// <param name="cutMode">Cut mode. Can be used to remove the data from the source when pasting it to the destination or immediately.</param> public static RangeData LoadData(GridVirtual sourceGrid, Range sourceRange, CutMode cutMode) { RangeData data = new RangeData(sourceGrid); //mCutMode = cutMode; data.mSourceRange = sourceRange; data.mSourceValues = new object[sourceRange.RowsCount, GetVisibleColumnCount(sourceGrid, sourceRange)]; int arrayRow = 0; for (int r = sourceRange.Start.Row; r <= sourceRange.End.Row; r++, arrayRow++) { int arrayCol = 0; for (int c = sourceRange.Start.Column; c <= sourceRange.End.Column; c++) { if (sourceGrid.Columns.IsColumnVisible(c) == false) { continue; } Position posCell = new Position(r, c); Cells.ICellVirtual cell = sourceGrid.GetCell(posCell); CellContext cellContext = new CellContext(sourceGrid, posCell, cell); /*if (cell != null && cell.Editor != null && cell.Editor.IsStringConversionSupported()) * data.mSourceValues[arrayRow, arrayCol] = cell.Editor.ValueToString( cell.Model.ValueModel.GetValue(cellContext) ); * else if (cell != null) * data.mSourceValues[arrayRow, arrayCol] = cellContext.DisplayText;*/ if (cell != null) { data.mSourceValues[arrayRow, arrayCol] = cellContext.Value; } arrayCol++; } } //Cut Data if (cutMode == CutMode.CutImmediately && sourceGrid != null) { sourceGrid.ClearValues(new RangeRegion(sourceRange)); } data.mClipboardDataObject = new System.Windows.Forms.DataObject(); data.mClipboardDataObject.SetData(RANGEDATA_FORMAT, data); string[,] values = DataToStringArray(sourceGrid, data.mSourceRange); data.mClipboardDataObject.SetData(typeof(string), StringArrayToString(values)); return(data); }
private void grid_KeyDown(GridVirtual sender, KeyEventArgs e) { if (e.Handled) { return; } if (sender.Selection.IsEmpty()) { return; } if (e.KeyCode == Keys.Delete) { sender.ClearValues(sender.Selection.GetSelectionRegion()); e.Handled = true; } }
/// <summary> /// Load the specified range data into a string array. This method use the cell editor to get the value. /// </summary> /// <param name="sourceGrid"></param> /// <param name="sourceRange"></param> /// <param name="cutMode">Cut mode. Can be used to remove the data from the source when pasting it to the destination or immediately.</param> public static RangeData LoadData(GridVirtual sourceGrid, Range sourceRange, CutMode cutMode) { RangeData data = new RangeData(sourceGrid); //mCutMode = cutMode; data.mSourceRange = sourceRange; data.mSourceValues = new object[sourceRange.RowsCount, GetVisibleColumnCount(sourceGrid, sourceRange)]; int arrayRow = 0; for (int r = sourceRange.Start.Row; r <= sourceRange.End.Row; r++, arrayRow++) { int arrayCol = 0; for (int c = sourceRange.Start.Column; c <= sourceRange.End.Column; c++) { if (sourceGrid.Columns.IsColumnVisible(c) == false) { continue; } Position posCell = new Position(r, c); Cells.ICellVirtual cell = sourceGrid.GetCell(posCell); CellContext cellContext = new CellContext(sourceGrid, posCell, cell); /*if (cell != null && cell.Editor != null && cell.Editor.IsStringConversionSupported()) * data.mSourceValues[arrayRow, arrayCol] = cell.Editor.ValueToString( cell.Model.ValueModel.GetValue(cellContext) ); * else if (cell != null) * data.mSourceValues[arrayRow, arrayCol] = cellContext.DisplayText;*/ //[email protected] : LoadData method is changed to support cut and copy activities. if (cell != null) { if (cutMode == CutMode.CutImmediately) { if ((cell.ClipboardModes & ClipboardMode.Cut) == ClipboardMode.Cut) { data.mSourceValues[arrayRow, arrayCol] = cellContext.Value; } } else if (cutMode == CutMode.None) { if ((cell.ClipboardModes & ClipboardMode.Copy) == ClipboardMode.Copy) { data.mSourceValues[arrayRow, arrayCol] = cellContext.Value; } } } arrayCol++; } } data.mClipboardDataObject = new System.Windows.Forms.DataObject(); data.mClipboardDataObject.SetData(RANGEDATA_FORMAT, data); string[,] values = DataToStringArray(sourceGrid, data.mSourceRange); data.mClipboardDataObject.SetData(typeof(string), StringArrayToString(values)); //Cut Data //[email protected] : Cut operation is moved below the copy operation to retain the data if (cutMode == CutMode.CutImmediately && sourceGrid != null) { sourceGrid.ClearValues(new RangeRegion(sourceRange), ClipboardMode.Cut); } return(data); }