//Event Customization public void model_ClipboardPaste(object sender, GridCutPasteEventArgs e) { GridRangeInfoList rangeList; GridModel model = sender as GridModel; model.Selections.GetSelectedRanges(out rangeList, true); GridRangeInfo range = rangeList.GetOuterRange(rangeList.ActiveRange); string psz = GetClipboardText(); this.PasteTextFromBuffer(psz, range, e.ClipboardFlags); e.Handled = true; }
/// <summary> /// Customization for copying the data from grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void gridControl1_ClipboardCopy(object sender, GridCutPasteEventArgs e) { e.Handled = true; this.CopyStylesAsBiffToClipBoard(e.RangeList); this.gridControl1.Model.CutPaste.CopyCellsToClipboard(e.RangeList, true); }
/// <summary> /// Customization for Pasting the data to grid /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void gridControl1_ClipboardCanPaste(object sender, GridCutPasteEventArgs e) { IDataObject dataObject = Clipboard.GetDataObject(); if (dataObject != null) { if (dataObject.GetDataPresent("Biff", true)) { ExcelEngine xlEngine = new ExcelEngine(); IApplication app = xlEngine.Excel; IWorkbooks workBook = app.Workbooks; workBook.PasteWorkbook(); IWorkbook book = workBook[0]; IWorksheet worksheet = book.Worksheets[0]; IRange ur = worksheet.UsedRange; IRange[] ranges = ur.Cells;//worksheet.UsedCells; System.Text.StringBuilder str = new System.Text.StringBuilder(); int lastCol = ranges[0].Column, lastRow = ranges[0].Row; int rc = ur.LastRow - ur.Row + 1; int cc = ur.LastColumn - ur.Column + 1; GridExcelConverterControl converter = new GridExcelConverterControl(); GridModel model = new GridModel(); model.ColCount = cc; model.RowCount = rc; ur.MoveTo(worksheet.Range[1, 1, rc, cc]); ranges = worksheet.Range[1, 1, rc, cc].Cells; foreach (IRange cell in ranges) { converter.ConvertExcelRangeToGrid(cell, model); } GridData data = new GridData(); data.InsertRows(1, rc); data.InsertCols(1, cc); for (int i = 1; i <= model.Data.RowCount; i++) { for (int j = 1; j <= model.ColCount; j++) { if (model.Data[i, j] != null) { data[i - 1, j - 1] = model.Data[i, j].Clone() as GridStyleInfoStore; } } } //Clipboard.Clear(); DataObject newDataObject = new DataObject(data); Clipboard.SetDataObject(newDataObject, true); xlEngine.ThrowNotSavedOnDestroy = false; xlEngine.Dispose(); } } }
void gridControl1_ClipboardCut(object sender, GridCutPasteEventArgs e) { e.ClipboardFlags = GridDragDropFlags.ColHeader; }