public LoadData ( |
||
sourceGrid | ||
sourceRange | ||
startDragPosition | Starting drag position. Used only for calculating drop destination range. | |
cutMode | CutMode | Cut mode. Can be used to remove the data from the source when pasting it to the destination or immediately. |
return | void |
/// <summary> /// Get a RangeData object from the clipboard. Return null if the clipboard doesn't contains valid data formats. /// </summary> /// <returns></returns> public static RangeData ClipboardGetData() { System.Windows.Forms.IDataObject dtObj = System.Windows.Forms.Clipboard.GetDataObject(); RangeData rngData = null; if (dtObj.GetDataPresent(RANGEDATA_FORMAT)) { rngData = (RangeData)dtObj.GetData(RANGEDATA_FORMAT); } else { if (dtObj.GetDataPresent(System.Windows.Forms.DataFormats.Text, true)) { string buffer = (string)dtObj.GetData(System.Windows.Forms.DataFormats.Text, true); rngData = new RangeData(); rngData.LoadData(buffer); } } return(rngData); }
/// <summary> /// Get a RangeData object from the clipboard. Return null if the clipboard doesn't contains valid data formats. /// </summary> /// <returns></returns> public static RangeData ClipboardGetData() { System.Windows.Forms.IDataObject dtObj = System.Windows.Forms.Clipboard.GetDataObject(); RangeData rngData = null; if (dtObj.GetDataPresent(RANGEDATA_FORMAT)) { rngData = (RangeData)dtObj.GetData(RANGEDATA_FORMAT); } // if RANGEDATA_FORMAT or GetData returns null use string buffer as rngData if (rngData == null) { // get unicode text instead of text if (dtObj.GetDataPresent(System.Windows.Forms.DataFormats.UnicodeText, true)) { string buffer = (string)dtObj.GetData(System.Windows.Forms.DataFormats.UnicodeText, true); rngData = new RangeData(); rngData.LoadData(buffer); } } return(rngData); }
/// <summary> /// Get a RangeData object from the clipboard. Return null if the clipboard doesn't contains valid data formats. /// </summary> /// <returns></returns> public static RangeData ClipboardGetData() { System.Windows.Forms.IDataObject dtObj = System.Windows.Forms.Clipboard.GetDataObject(); RangeData rngData = null; if (dtObj.GetDataPresent(RANGEDATA_FORMAT)) rngData = (RangeData)dtObj.GetData(RANGEDATA_FORMAT); else { if (dtObj.GetDataPresent(System.Windows.Forms.DataFormats.Text, true)) { string buffer = (string)dtObj.GetData(System.Windows.Forms.DataFormats.Text,true); rngData = new RangeData(); rngData.LoadData(buffer); } } return rngData; }
/// <summary> /// Process Delete, Ctrl+C, Ctrl+V, Up, Down, Left, Right, Tab keys /// </summary> /// <param name="e"></param> public virtual void ProcessSpecialGridKey(KeyEventArgs e) { if (e.Handled) return; bool enableArrows,enableTab,enablePageDownUp; enableArrows = enableTab = enablePageDownUp = false; if ( (SpecialKeys & GridSpecialKeys.Arrows) == GridSpecialKeys.Arrows) enableArrows = true; if ( (SpecialKeys & GridSpecialKeys.PageDownUp) == GridSpecialKeys.PageDownUp) enablePageDownUp = true; if ( (SpecialKeys & GridSpecialKeys.Tab) == GridSpecialKeys.Tab) enableTab = true; bool enableEscape = false; if ( (SpecialKeys & GridSpecialKeys.Escape) == GridSpecialKeys.Escape) enableEscape = true; bool enableEnter = false; if ( (SpecialKeys & GridSpecialKeys.Enter) == GridSpecialKeys.Enter) enableEnter = true; #region Processing keys //Escape if (e.KeyCode == Keys.Escape && enableEscape) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { if (focusCellContext.EndEdit(true)) e.Handled = true; } } //Enter if (e.KeyCode == Keys.Enter && enableEnter) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { focusCellContext.EndEdit(false); e.Handled = true; } } //Tab if (e.KeyCode == Keys.Tab && enableTab) { CellContext focusCellContext = new CellContext(this, Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing()) { //se l'editing non riesce considero il tasto processato // altrimenti no, in questo modo il tab ha effetto anche per lo spostamento if (focusCellContext.EndEdit(false) == false) { e.Handled = true; return; } } } #endregion #region Navigate keys: arrows, tab and PgDown/Up if (e.KeyCode == Keys.Down && enableArrows) { Selection.MoveActiveCell(1, 0); e.Handled = true; } else if (e.KeyCode == Keys.Up && enableArrows) { Selection.MoveActiveCell(-1, 0); e.Handled = true; } else if (e.KeyCode == Keys.Right && enableArrows) { Selection.MoveActiveCell(0, 1); e.Handled = true; } else if (e.KeyCode == Keys.Left && enableArrows) { Selection.MoveActiveCell(0, -1); e.Handled = true; } else if (e.KeyCode == Keys.Tab && enableTab) { //If the tab failed I automatically select the next control in the form (SelectNextControl) if (e.Modifiers == Keys.Shift) // backward { if (Selection.MoveActiveCell(0, -1, -1, int.MaxValue) == false) FindForm().SelectNextControl(this, false, true, true, true); e.Handled = true; } else //forward { if (Selection.MoveActiveCell(0, 1, 1, int.MinValue) == false) FindForm().SelectNextControl(this, true, true, true, true); e.Handled = true; } } else if ( (e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown) && enablePageDownUp) { Point focusPoint = PositionToRectangle(Selection.ActivePosition).Location; focusPoint.Offset(1, 1); //in modo da entrare nella cella if (e.KeyCode == Keys.PageDown) CustomScrollPageDown(); else if (e.KeyCode == Keys.PageUp) CustomScrollPageUp(); Position newPosition = PositionAtPoint(focusPoint); if (Selection.CanReceiveFocus(newPosition)) Selection.Focus(newPosition, true); e.Handled = true; } #endregion #region Clipboard bool pasteEnabled = (ClipboardMode & ClipboardMode.Paste) == ClipboardMode.Paste; bool copyEnabled = (ClipboardMode & ClipboardMode.Copy) == ClipboardMode.Copy; bool cutEnabled = (ClipboardMode & ClipboardMode.Cut) == ClipboardMode.Cut; bool deleteEnabled = (ClipboardMode & ClipboardMode.Delete) == ClipboardMode.Delete; RangeRegion selRegion = Selection.GetSelectionRegion(); //Paste if (e.Control && e.KeyCode == Keys.V && pasteEnabled && selRegion.IsEmpty() == false) { RangeData rngData = RangeData.ClipboardGetData(); if (rngData != null) { Range rng = selRegion.GetRanges()[0]; Range destinationRange = rngData.FindDestinationRange(this, rng.Start); rngData.WriteData(this, destinationRange); e.Handled = true; Selection.ResetSelection(true); Selection.SelectRange(destinationRange, true); } } //Copy else if (e.Control && e.KeyCode == Keys.C && copyEnabled && selRegion.IsEmpty() == false) { Range rng = selRegion.GetRanges()[0]; RangeData data = new RangeData(); data.LoadData(this, rng, rng.Start, CutMode.None); RangeData.ClipboardSetData(data); e.Handled = true; } //Cut else if (e.Control && e.KeyCode == Keys.X && cutEnabled && selRegion.IsEmpty() == false) { Range rng = selRegion.GetRanges()[0]; RangeData data = new RangeData(); data.LoadData(this, rng, rng.Start, CutMode.CutImmediately); RangeData.ClipboardSetData(data); e.Handled = true; } //Delete else if (e.KeyCode == Keys.Delete && deleteEnabled) { ClearValues(selRegion); e.Handled = true; } #endregion }
/// <summary> /// Get a RangeData object from the clipboard. Return null if the clipboard doesn't contains valid data formats. /// </summary> /// <returns></returns> public static RangeData ClipboardGetData() { System.Windows.Forms.IDataObject dtObj = System.Windows.Forms.Clipboard.GetDataObject(); RangeData rngData = null; if (dtObj.GetDataPresent(RANGEDATA_FORMAT)) rngData = (RangeData)dtObj.GetData(RANGEDATA_FORMAT); // if RANGEDATA_FORMAT or GetData returns null use string buffer as rngData if (rngData == null) { // get unicode text instead of text if (dtObj.GetDataPresent(System.Windows.Forms.DataFormats.UnicodeText, true)) { string buffer = (string)dtObj.GetData(System.Windows.Forms.DataFormats.UnicodeText, true); rngData = new RangeData(); rngData.LoadData(buffer); } } return rngData; }