protected virtual void grid_MouseMove(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { Position l_PointPosition = sender.PositionAtPoint(new Point(e.X, e.Y)); Cells.ICellVirtual l_CellPosition = sender.GetCell(l_PointPosition); //Call MouseMove on the cell that receive tha MouseDown event if (sender.MouseDownPosition.IsEmpty() == false) { Cells.ICellVirtual l_MouseDownCell = sender.GetCell(sender.MouseDownPosition); if (l_MouseDownCell != null) { sender.Controller.OnMouseMove(new CellContext(sender, sender.MouseDownPosition, l_MouseDownCell), e); } } else //se non ho nessuna cella attualmente che ha ricevuto un mousedown, l'evento di MouseMove viene segnalato sulla cella correntemente sotto il Mouse { // se non c'è nessuna cella MouseDown cambio la cella corrente sotto il Mouse #if !MINI sender.ChangeMouseCell(l_PointPosition); //in ogni caso cambio la cella corrente #endif if (l_PointPosition.IsEmpty() == false && l_CellPosition != null) { // I call MouseMove on the current cell only if there aren't any cells under the mouse sender.Controller.OnMouseMove(new CellContext(sender, l_PointPosition, l_CellPosition), e); } } }
/// <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) { mSourceValues[arrayRow, arrayCol] = cell.Editor.ValueToString(cell.Model.ValueModel.GetValue(cellContext)); } else if (cell != null) { mSourceValues[arrayRow, arrayCol] = cellContext.GetDisplayText(); } } } //Cut Data if (CutMode == CutMode.CutImmediately && sourceGrid != null) { 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)); }
protected virtual void grid_MouseDown(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { //verifico che l'eventuale edit sia terminato altrimenti esco if (sender.Selection.ActivePosition.IsEmpty() == false) { CellContext focusCell = new CellContext(sender, sender.Selection.ActivePosition); if (focusCell.Cell != null && focusCell.IsEditing()) { if (focusCell.EndEdit(false) == false) return; } } //scateno eventi di MouseDown Position position = sender.PositionAtPoint( new Point(e.X, e.Y) ); if (position.IsEmpty() == false) { Cells.ICellVirtual cellMouseDown = sender.GetCell(position); if (cellMouseDown != null) { sender.ChangeMouseDownCell(position, position); //Cell.OnMouseDown CellContext cellContext = new CellContext(sender, position, cellMouseDown); sender.Controller.OnMouseDown(cellContext, e); } } else sender.ChangeMouseDownCell(Position.Empty, Position.Empty); }
/// <summary> /// Convert a range and an array of string into a string. Normally using a tab delimited for columns and a LineFeed for rows. /// </summary> /// <returns></returns> protected static string[,] DataToStringArray(GridVirtual sourceGrid, Range range) { int numberOfRows = range.End.Row - range.Start.Row + 1; int numberOfCols = range.End.Column - range.Start.Column + 1; string[,] values = new string[numberOfRows, numberOfCols]; int arrayRow = 0; for (int r = range.Start.Row; r <= range.End.Row; r++, arrayRow++) { int arrayCol = 0; for (int c = range.Start.Column; c <= range.End.Column; c++, arrayCol++) { String val = String.Empty; 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()) { values[arrayRow, arrayCol] = cell.Editor.ValueToString(cell.Model.ValueModel.GetValue(cellContext)); } else if (cell != null) { values[arrayRow, arrayCol] = cellContext.DisplayText; } } } return(values); }
protected virtual void grid_MouseDown(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { //verifico che l'eventuale edit sia terminato altrimenti esco if (sender.Selection.ActivePosition.IsEmpty() == false) { CellContext focusCell = new CellContext(sender, sender.Selection.ActivePosition); if (focusCell.Cell != null && focusCell.IsEditing()) { if (focusCell.EndEdit(false) == false) { return; } } } //scateno eventi di MouseDown Position position = sender.PositionAtPoint(new Point(e.X, e.Y)); if (position.IsEmpty() == false) { Cells.ICellVirtual cellMouseDown = sender.GetCell(position); if (cellMouseDown != null) { sender.ChangeMouseDownCell(position, position); //Cell.OnMouseDown CellContext cellContext = new CellContext(sender, position, cellMouseDown); sender.Controller.OnMouseDown(cellContext, e); } } else { sender.ChangeMouseDownCell(Position.Empty, Position.Empty); } }
protected virtual void grid_DragEnter(GridVirtual sender, System.Windows.Forms.DragEventArgs e) { Position pointPosition = sender.PositionAtPoint(sender.PointToClient(new Point(e.X, e.Y))); Cells.ICellVirtual cellPosition = sender.GetCell(pointPosition); sender.ChangeDragCell(new CellContext(sender, pointPosition, cellPosition), e); }
protected virtual void grid_GiveFeedback(GridVirtual sender, System.Windows.Forms.GiveFeedbackEventArgs e) { Position dragPosition = sender.DragCellPosition; Cells.ICellVirtual cellPosition = sender.GetCell(dragPosition); sender.Controller.OnGiveFeedback(new CellContext(sender, dragPosition, cellPosition), e); }
protected virtual void grid_MouseDown(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { //verifico che l'eventuale edit sia terminato altrimenti esco if (sender.Selection.ActivePosition.IsEmpty() == false) { //Se la cella coincide esco if (sender.MouseDownPosition == sender.Selection.ActivePosition) { return; } //Altrimenti provo a terminare l'edit CellContext focusCell = new CellContext(sender, sender.Selection.ActivePosition); if (focusCell.Cell != null && focusCell.IsEditing()) { if (focusCell.EndEdit(false) == false) { return; } } } //scateno eventi di MouseDown e seleziono la cella if (sender.MouseDownPosition.IsEmpty() == false) { Cells.ICellVirtual cellMouseDown = sender.GetCell(sender.MouseDownPosition); if (cellMouseDown != null) { int distance; DevAge.Drawing.RectanglePartType partType = sender.Selection.Border.PointToPartType(sender.Selection.GetDrawingRectangle(), new System.Drawing.Point(e.X, e.Y), out distance); if (partType == DevAge.Drawing.RectanglePartType.ContentArea || partType == DevAge.Drawing.RectanglePartType.None) { bool l_bShiftPress = ((Control.ModifierKeys & Keys.Shift) == Keys.Shift && (sender.SpecialKeys & GridSpecialKeys.Shift) == GridSpecialKeys.Shift); if (l_bShiftPress == false || sender.Selection.EnableMultiSelection == false || sender.Selection.ActivePosition.IsEmpty()) { //Standard focus on the cell on MouseDown if (sender.Selection.Contains(sender.MouseDownPosition) == false || e.Button == MouseButtons.Left) //solo se non è stata ancora selezionata { sender.Selection.Focus(sender.MouseDownPosition); } } else //gestione speciale caso shift { sender.Selection.Clear(); Range rangeToSelect = new Range(sender.Selection.ActivePosition, sender.MouseDownPosition); sender.Selection.Add(rangeToSelect); } } } } }
/// <summary> /// Write the current loaded array string in the specified grid range. This method use the cell editor to set the value. /// </summary> public void WriteData(GridVirtual sourceGrid, Position destinationPosition) { int sourceRow = this.SourceValues.GetUpperBound(0); int sourceColumn = this.SourceValues.GetUpperBound(1); var dataRow = 0; for (int r = destinationPosition.Row; r <= destinationPosition.Row + sourceRow; r++) { int dataColumn = 0; for (int c = destinationPosition.Column; c <= destinationPosition.Column + sourceColumn; c++) { Position posCell = new Position(r, c); Cells.ICellVirtual cell = sourceGrid.GetCell(posCell); CellContext cellContext = new CellContext(sourceGrid, posCell, cell); //[email protected] : WriteData method is changed to support paste activity. if (cell != null && (cell.ClipboardModes & ClipboardMode.Paste) == ClipboardMode.Paste && cell.Editor != null && mSourceValues[dataRow, dataColumn] != null) { cell.Editor.SetCellValue(cellContext, mSourceValues[dataRow, dataColumn]); } dataColumn++; } dataRow++; } /*int sourceRow = this.SourceValues.Length - 1; * int sourceColumn = this.SourceValues.Rank - 1; * //Calculate the destination Range merging the source range * var destinationRange = new Range(destinationPosition, * new Position(destinationPosition.Row + sourceRow, destinationPosition.Column + sourceColumn)); * Range newRange = mSourceRange; * newRange.MoveTo(destinationRange.Start); * if (newRange.End.Column > destinationRange.End.Column) * newRange.End = new Position(newRange.End.Row, destinationRange.End.Column); * if (newRange.End.Row > destinationRange.End.Row) * newRange.End.Row = destinationRange.End.Row; * * for (int r = newRange.Start.Row; r <= newRange.End.Row; r++) * { * int dataColumn = 0; * for (int c = newRange.Start.Column; c <= newRange.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 && mSourceValues[r - newRange.Start.Row, dataColumn] != null) * cell.Editor.SetCellValue(cellContext, mSourceValues[r - newRange.Start.Row, dataColumn] ); * dataColumn++; * } * }*/ }
protected virtual void grid_DoubleClick(GridVirtual sender, EventArgs e) { if (sender.MouseDownPosition.IsEmpty() == false) { Cells.ICellVirtual l_MouseDownCell = sender.GetCell(sender.MouseDownPosition); if (l_MouseDownCell != null) { sender.Controller.OnDoubleClick(new CellContext(sender, sender.MouseDownPosition, l_MouseDownCell), EventArgs.Empty); } } }
protected virtual void grid_KeyUp(GridVirtual sender, System.Windows.Forms.KeyEventArgs e) { if (sender.Selection.ActivePosition.IsEmpty() == false) { Cells.ICellVirtual l_FocusCell = sender.GetCell(sender.Selection.ActivePosition); if (l_FocusCell != null) { sender.Controller.OnKeyUp(new CellContext(sender, sender.Selection.ActivePosition, l_FocusCell), e); } } }
/// <summary> /// Returns the union of all the selected range as Position collection /// </summary> /// <returns></returns> public virtual CellCollection GetCells() { CellCollection cells = new CellCollection(); PositionCollection l_Positions = GetCellsPositions(); for (int i = 0; i < l_Positions.Count; i++) { cells.Add(m_Grid.GetCell(l_Positions[i])); } return(cells); }
protected virtual void grid_MouseUp(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { if (sender.MouseDownPosition.IsEmpty() == false) { Cells.ICellVirtual l_MouseDownCell = sender.GetCell(sender.MouseDownPosition); if (l_MouseDownCell != null) { sender.Controller.OnMouseUp(new CellContext(sender, sender.MouseDownPosition, l_MouseDownCell), e); } sender.ChangeMouseDownCell(Position.Empty, sender.PositionAtPoint(new Point(e.X, e.Y))); } }
/// <summary> /// Write the current loaded array string in the specified grid range. This method use the cell editor to set the value. /// </summary> /// <param name="destinationGrid"></param> /// <param name="destinationRange"></param> public void WriteData(GridVirtual destinationGrid, Range destinationRange) { //Calculate the destination Range merging the source range Range newRange = mSourceRange; newRange.MoveTo(destinationRange.Start); if (newRange.ColumnsCount > destinationRange.ColumnsCount) { newRange.ColumnsCount = destinationRange.ColumnsCount; } if (newRange.RowsCount > destinationRange.RowsCount) { newRange.RowsCount = destinationRange.RowsCount; } //Cut Data if (CutMode == CutMode.CutOnPaste && mSourceGrid != null) { for (int sr = mSourceRange.Start.Row; sr <= mSourceRange.End.Row; sr++) { for (int sc = mSourceRange.Start.Column; sc <= mSourceRange.End.Column; sc++) { Position pos = new Position(sr, sc); Cells.ICellVirtual cell = mSourceGrid.GetCell(sr, sc); CellContext cellContext = new CellContext(mSourceGrid, pos, cell); if (cell.Editor != null) { cell.Editor.ClearCell(cellContext); } } } } int arrayRow = 0; for (int r = newRange.Start.Row; r <= newRange.End.Row; r++, arrayRow++) { int arrayCol = 0; for (int c = newRange.Start.Column; c <= newRange.End.Column; c++, arrayCol++) { Position posCell = new Position(r, c); Cells.ICellVirtual cell = destinationGrid.GetCell(posCell); CellContext cellContext = new CellContext(destinationGrid, posCell, cell); if (cell != null && cell.Editor != null && mSourceValues[arrayRow, arrayCol] != null) { cell.Editor.SetCellValue(cellContext, mSourceValues[arrayRow, arrayCol]); } } } }
protected virtual void grid_MouseMove(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { Position l_PointPosition = sender.PositionAtPoint(new Point(e.X, e.Y)); Cells.ICellVirtual l_CellPosition = sender.GetCell(l_PointPosition); #region Mouse Multiselection if (e.Button == MouseButtons.Left && sender.Selection.EnableMultiSelection) { //Only if there is a FocusCell CellContext focusCellContext = new CellContext(sender, sender.Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing() == false) { Position l_SelCornerPos = l_PointPosition; Cells.ICellVirtual l_SelCorner = l_CellPosition; //If the current Focus Cell is a scrollable cell then search the current cell (under the mouse)only in scrollable cells // see PositionAtPoint with false parameter if (sender.GetPositionType(sender.Selection.ActivePosition) == CellPositionType.Scrollable) { l_SelCornerPos = sender.PositionAtPoint(new Point(e.X, e.Y)); l_SelCorner = sender.GetCell(l_PointPosition); } if (l_SelCornerPos.IsEmpty() == false && l_SelCorner != null) { //Only if the user start the selection with a cell (m_MouseDownCell!=null) if (sender.MouseDownPosition.IsEmpty() == false && sender.Selection.Contains(sender.MouseDownPosition)) { sender.ChangeMouseSelectionCorner(l_SelCornerPos); sender.ShowCell(l_SelCornerPos); } } } } #endregion }
private void grid_KeyPress(GridVirtual sender, System.Windows.Forms.KeyPressEventArgs e) { //solo se diverso da tab e da a capo ( e non è un comando di copia/incolla) if (sender.Selection.ActivePosition.IsEmpty() || e.KeyChar == '\t' || e.KeyChar == 13 || e.KeyChar == 3 || e.KeyChar == 22 || e.KeyChar == 24) { } else { Cells.ICellVirtual l_FocusCell = sender.GetCell(sender.Selection.ActivePosition); if (l_FocusCell != null) { sender.Controller.OnKeyPress(new CellContext(sender, sender.Selection.ActivePosition, l_FocusCell), e); } } }
/// <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); }
public void Export(GridVirtual grid) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Stream, System.Text.Encoding.UTF8); //write HTML and BODY if ((Mode & ExportHTMLMode.HTMLAndBody) == ExportHTMLMode.HTMLAndBody) { writer.WriteStartElement("html"); writer.WriteStartElement("body"); } writer.WriteStartElement("table"); writer.WriteAttributeString("cellspacing", "0"); writer.WriteAttributeString("cellpadding", "0"); for (int r = 0; r < grid.Rows.Count; r++) { writer.WriteStartElement("tr"); for (int c = 0; c < grid.Columns.Count; c++) { Cells.ICellVirtual cell = grid.GetCell(r, c); Position pos = new Position(r, c); CellContext context = new CellContext(grid, pos, cell); ExportHTMLCell(context, writer); } //tr writer.WriteEndElement(); } //table writer.WriteEndElement(); //write end HTML and BODY if ((Mode & ExportHTMLMode.HTMLAndBody) == ExportHTMLMode.HTMLAndBody) { //body writer.WriteEndElement(); //html writer.WriteEndElement(); } writer.Flush(); }
public virtual void Export(GridVirtual grid, System.Drawing.Graphics graphics, Range rangeToExport, System.Drawing.Point destinationLocation) { if (rangeToExport.IsEmpty()) { return; } System.Drawing.Point cellPoint = destinationLocation; System.Drawing.Point deltaPoint = destinationLocation; using (DevAge.Drawing.GraphicsCache graphicsCache = new DevAge.Drawing.GraphicsCache(graphics)) { for (int r = rangeToExport.Start.Row; r <= rangeToExport.End.Row; r++) { int rowHeight = grid.Rows.GetHeight(r); for (int c = rangeToExport.Start.Column; c <= rangeToExport.End.Column; c++) { System.Drawing.Rectangle cellRectangle; Position pos = new Position(r, c); Range range = grid.PositionToCellRange(pos); System.Drawing.Size cellSize = new System.Drawing.Size(grid.Columns.GetWidth(c), rowHeight); if (range.ColumnsCount > 1 || range.RowsCount > 1) //support for RowSpan or ColSpan { System.Drawing.Rectangle rangeRectange = grid.RangeToRectangleRelative(rangeToExport.Start.Row, rangeToExport.Start.Column, range); cellRectangle = new System.Drawing.Rectangle(new System.Drawing.Point(deltaPoint.X + rangeRectange.Location.X, deltaPoint.Y + rangeRectange.Location.Y), rangeRectange.Size); } else { cellRectangle = new System.Drawing.Rectangle(cellPoint, cellSize); } Cells.ICellVirtual cell = grid.GetCell(pos); CellContext context = new CellContext(grid, pos, cell); ExportCell(context, graphicsCache, cellRectangle); cellPoint = new System.Drawing.Point(cellPoint.X + cellSize.Width, cellPoint.Y); } cellPoint = new System.Drawing.Point(destinationLocation.X, cellPoint.Y + rowHeight); } } }
public virtual void Export(GridVirtual grid, System.IO.TextWriter stream) { for (int r = 0; r < grid.Rows.Count; r++) { for (int c = 0; c < grid.Columns.Count; c++) { if (c > 0) stream.Write(mFieldSeparator); Cells.ICellVirtual cell = grid.GetCell(r, c); Position pos = new Position(r, c); CellContext context = new CellContext(grid, pos, cell); ExportCSVCell(context, stream); } stream.Write(mLineSeparator); } }
protected virtual void grid_Click(GridVirtual sender, EventArgs e) { Position clickPosition = sender.PositionAtPoint(sender.PointToClient(Control.MousePosition)); Position clickStartPosition = sender.PositionToStartPosition(clickPosition); //Se ho precedentemente scatenato un MouseDown su una cella // e se questa corrisponde alla cella sotto il puntatore del mouse (non posso usare MouseCellPosition perchè questa viene aggiornata solo quando non si ha una cella come MouseDownPosition if (sender.MouseDownPosition.IsEmpty() == false && sender.MouseDownPosition == clickStartPosition /* MouseCellPosition && * m_MouseDownCell.Focused == true //tolto altrimenti non funzionava per le celle Selectable==false*/) { Cells.ICellVirtual mouseDownCell = sender.GetCell(sender.MouseDownPosition); if (mouseDownCell != null) { sender.Controller.OnClick(new CellContext(sender, sender.MouseDownPosition, mouseDownCell), EventArgs.Empty); } } }
public virtual void Export(GridVirtual grid, System.IO.TextWriter stream) { for (int r = 0; r < grid.Rows.Count; r++) { for (int c = 0; c < grid.Columns.Count; c++) { if (c > 0) { stream.Write(mFieldSeparator); } Cells.ICellVirtual cell = grid.GetCell(r, c); Position pos = new Position(r, c); CellContext context = new CellContext(grid, pos, cell); ExportCSVCell(context, stream); } stream.Write(mLineSeparator); } }
/// <summary> /// Returns the union of all the selected range as Position collection /// </summary> /// <returns></returns> public CellVirtualCollection GetCells() { if (m_CellBaseListCache == null) { m_CellBaseListCache = new CellVirtualCollection(); PositionCollection l_Positions = GetCellsPositions(); for (int i = 0; i < l_Positions.Count; i++) { m_CellBaseListCache.Add(m_Grid.GetCell(l_Positions[i])); } } return(m_CellBaseListCache); }
public virtual void Export(GridVirtual grid, System.IO.TextWriter stream) { for (var r = 0; r < grid.Rows.Count; r++) { for (var c = 0; c < grid.Columns.Count; c++) { if (c > 0) { stream.Write(mFieldSeparator); } var cell = grid.GetCell(r, c); var pos = new Position(r, c); var context = new CellContext(grid, pos, cell); ExportCsvCell(context, stream); } if (IsLastLine(grid, r) == false) { stream.Write(mLineSeparator); } } }
protected virtual void grid_DragOver(GridVirtual sender, System.Windows.Forms.DragEventArgs e) { Position pointPosition = sender.PositionAtPoint(sender.PointToClient( new Point(e.X, e.Y) )); Cells.ICellVirtual cellPosition = sender.GetCell(pointPosition); CellContext cellContext = new CellContext(sender, pointPosition, cellPosition); sender.ChangeDragCell(cellContext, e); sender.Controller.OnDragOver(cellContext, e); }
protected virtual void grid_MouseMove(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { Position l_PointPosition = sender.PositionAtPoint(new Point(e.X, e.Y)); Cells.ICellVirtual l_CellPosition = sender.GetCell(l_PointPosition); //Call MouseMove on the cell that receive tha MouseDown event if (sender.MouseDownPosition.IsEmpty() == false) { Cells.ICellVirtual l_MouseDownCell = sender.GetCell(sender.MouseDownPosition); if (l_MouseDownCell!=null) { sender.Controller.OnMouseMove(new CellContext(sender, sender.MouseDownPosition, l_MouseDownCell), e); } } else //se non ho nessuna cella attualmente che ha ricevuto un mousedown, l'evento di MouseMove viene segnalato sulla cella correntemente sotto il Mouse { // se non c'è nessuna cella MouseDown cambio la cella corrente sotto il Mouse #if !MINI sender.ChangeMouseCell(l_PointPosition);//in ogni caso cambio la cella corrente #endif if (l_PointPosition.IsEmpty() == false && l_CellPosition != null) { // I call MouseMove on the current cell only if there aren't any cells under the mouse sender.Controller.OnMouseMove(new CellContext(sender, l_PointPosition, l_CellPosition), e); } } }
public virtual void Export(GridVirtual grid, System.Drawing.Graphics graphics, Range rangeToExport, System.Drawing.Point destinationLocation) { if (rangeToExport.IsEmpty()) return; System.Drawing.Point cellPoint = destinationLocation; using (DevAge.Drawing.GraphicsCache graphicsCache = new DevAge.Drawing.GraphicsCache(graphics)) { for (int r = rangeToExport.Start.Row; r <= rangeToExport.End.Row; r++) { int rowHeight = grid.Rows.GetHeight(r); for (int c = rangeToExport.Start.Column; c <= rangeToExport.End.Column; c++) { Rectangle cellRectangle; Position pos = new Position(r, c); Size cellSize = new Size(grid.Columns.GetWidth(c), rowHeight); Range range = grid.PositionToCellRange(pos); //support for RowSpan or ColSpan //Note: for now I draw only the merged cell at the first position // (this can cause a problem if you export partial range that contains a partial merged cells) if ( range.ColumnsCount > 1 || range.RowsCount > 1) { //Is the first position if (range.Start == pos) { Size rangeSize = grid.RangeToSize(range); cellRectangle = new Rectangle(cellPoint, rangeSize); } else cellRectangle = Rectangle.Empty; } else { cellRectangle = new Rectangle(cellPoint, cellSize); } if (cellRectangle.IsEmpty == false) { Cells.ICellVirtual cell = grid.GetCell(pos); CellContext context = new CellContext(grid, pos, cell); ExportCell(context, graphicsCache, cellRectangle); } cellPoint = new Point(cellPoint.X + cellSize.Width, cellPoint.Y); } cellPoint = new Point(destinationLocation.X, cellPoint.Y + rowHeight); } } }
protected virtual void grid_DoubleClick(GridVirtual sender, EventArgs e) { if (sender.MouseDownPosition.IsEmpty() == false) { Cells.ICellVirtual l_MouseDownCell = sender.GetCell(sender.MouseDownPosition); if (l_MouseDownCell!=null) { sender.Controller.OnDoubleClick(new CellContext(sender, sender.MouseDownPosition, l_MouseDownCell), EventArgs.Empty); } } }
protected virtual void grid_Click(GridVirtual sender, EventArgs e) { Position clickPosition = sender.PositionAtPoint(sender.PointToClient(Control.MousePosition)); Position clickStartPosition = sender.PositionToStartPosition(clickPosition); //Se ho precedentemente scatenato un MouseDown su una cella // e se questa corrisponde alla cella sotto il puntatore del mouse (non posso usare MouseCellPosition perchè questa viene aggiornata solo quando non si ha una cella come MouseDownPosition if (sender.MouseDownPosition.IsEmpty() == false && sender.MouseDownPosition == clickStartPosition /* MouseCellPosition && m_MouseDownCell.Focused == true //tolto altrimenti non funzionava per le celle Selectable==false*/) { Cells.ICellVirtual mouseDownCell = sender.GetCell(sender.MouseDownPosition); if (mouseDownCell != null) { sender.Controller.OnClick(new CellContext(sender, sender.MouseDownPosition, mouseDownCell), EventArgs.Empty); } } }
private void grid_KeyPress(GridVirtual sender, System.Windows.Forms.KeyPressEventArgs e) { //solo se diverso da tab e da a capo ( e non è un comando di copia/incolla) if (sender.Selection.ActivePosition.IsEmpty() || e.KeyChar == '\t' || e.KeyChar == 13 || e.KeyChar == 3 || e.KeyChar == 22 || e.KeyChar == 24) { } else { Cells.ICellVirtual l_FocusCell = sender.GetCell(sender.Selection.ActivePosition); if (l_FocusCell != null) sender.Controller.OnKeyPress( new CellContext(sender, sender.Selection.ActivePosition, l_FocusCell), e ); } }
protected virtual void grid_KeyUp(GridVirtual sender, System.Windows.Forms.KeyEventArgs e) { if (sender.Selection.ActivePosition.IsEmpty() == false) { Cells.ICellVirtual l_FocusCell = sender.GetCell(sender.Selection.ActivePosition); if (l_FocusCell!=null) sender.Controller.OnKeyUp(new CellContext(sender, sender.Selection.ActivePosition, l_FocusCell), e ); } }
protected virtual void grid_MouseUp(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { if (sender.MouseDownPosition.IsEmpty() == false) { Cells.ICellVirtual l_MouseDownCell = sender.GetCell(sender.MouseDownPosition); if (l_MouseDownCell!=null) sender.Controller.OnMouseUp(new CellContext(sender, sender.MouseDownPosition, l_MouseDownCell), e ); sender.ChangeMouseDownCell(Position.Empty, sender.PositionAtPoint(new Point(e.X, e.Y))); } }
/// <summary> /// Constructor /// </summary> /// <param name="pGridVirtual"></param> /// <param name="pPosition"></param> public CellContext(GridVirtual pGridVirtual, Position pPosition) { Position = pPosition; Grid = pGridVirtual; Cell = Grid.GetCell(Position); }
/// <summary> /// cast cell on position pos to Cell /// </summary> /// <param name="grid"></param> /// <param name="pos"></param> /// <returns></returns> private static SourceGrid.Cells.Cell GetCell(GridVirtual grid, Position pos) { return(grid.GetCell(pos) as SourceGrid.Cells.Cell); }
/// <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); }
public void Export(GridVirtual grid) { System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(Stream, System.Text.Encoding.UTF8); //write HTML and BODY if ( (Mode & ExportHTMLMode.HTMLAndBody) == ExportHTMLMode.HTMLAndBody) { writer.WriteStartElement("html"); writer.WriteStartElement("body"); } writer.WriteStartElement("table"); writer.WriteAttributeString("cellspacing","0"); writer.WriteAttributeString("cellpadding","0"); for (int r = 0; r < grid.Rows.Count; r++) { writer.WriteStartElement("tr"); for (int c = 0; c < grid.Columns.Count; c++) { Cells.ICellVirtual cell = grid.GetCell(r,c); Position pos = new Position(r,c); CellContext context = new CellContext(grid, pos, cell); ExportHTMLCell(context, writer); } //tr writer.WriteEndElement(); } //table writer.WriteEndElement(); //write end HTML and BODY if ( (Mode & ExportHTMLMode.HTMLAndBody) == ExportHTMLMode.HTMLAndBody) { //body writer.WriteEndElement(); //html writer.WriteEndElement(); } writer.Flush(); }
public virtual void Export(GridVirtual grid, System.Drawing.Graphics graphics, Range rangeToExport, System.Drawing.Point destinationLocation) { if (rangeToExport.IsEmpty()) { return; } System.Drawing.Point cellPoint = destinationLocation; using (DevAge.Drawing.GraphicsCache graphicsCache = new DevAge.Drawing.GraphicsCache(graphics)) { for (int r = rangeToExport.Start.Row; r <= rangeToExport.End.Row; r++) { int rowHeight = grid.Rows.GetHeight(r); for (int c = rangeToExport.Start.Column; c <= rangeToExport.End.Column; c++) { Rectangle cellRectangle; Position pos = new Position(r, c); Size cellSize = new Size(grid.Columns.GetWidth(c), rowHeight); Range range = grid.PositionToCellRange(pos); //support for RowSpan or ColSpan //Note: for now I draw only the merged cell at the first position // (this can cause a problem if you export partial range that contains a partial merged cells) if (range.ColumnsCount > 1 || range.RowsCount > 1) { //Is the first position if (range.Start == pos) { Size rangeSize = grid.RangeToSize(range); cellRectangle = new Rectangle(cellPoint, rangeSize); } else { cellRectangle = Rectangle.Empty; } } else { cellRectangle = new Rectangle(cellPoint, cellSize); } if (cellRectangle.IsEmpty == false) { Cells.ICellVirtual cell = grid.GetCell(pos); CellContext context = new CellContext(grid, pos, cell); ExportCell(context, graphicsCache, cellRectangle); } cellPoint = new Point(cellPoint.X + cellSize.Width, cellPoint.Y); } cellPoint = new Point(destinationLocation.X, cellPoint.Y + rowHeight); } } }
protected virtual void grid_MouseMove(GridVirtual sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left && sender.Selection.EnableMultiSelection) { //Scroll if necesary sender.ScrollOnPoint(e.Location); Position pointPosition = sender.PositionAtPoint(e.Location); Cells.ICellVirtual cellPosition = sender.GetCell(pointPosition); //Only if there is a FocusCell CellContext focusCellContext = new CellContext(sender, sender.Selection.ActivePosition); if (focusCellContext.Cell != null && focusCellContext.IsEditing() ==false) { Position selCornerPos = pointPosition; Cells.ICellVirtual selCorner = cellPosition; ////If the current Focus Cell is a scrollable cell then search the current cell (under the mouse)only in scrollable cells //// see PositionAtPoint with false parameter //if (sender.GetPositionType(sender.Selection.ActivePosition) == CellPositionType.Scrollable) //{ // selCornerPos = sender.PositionAtPoint(new Point(e.X, e.Y)); // selCorner = sender.GetCell(pointPosition); //} if (selCornerPos.IsEmpty() == false && selCorner != null) { //Only if the user start the selection with a cell (m_MouseDownCell!=null) if (sender.MouseDownPosition.IsEmpty() == false && sender.Selection.IsSelectedCell(sender.MouseDownPosition)) { sender.ChangeMouseSelectionCorner(selCornerPos); //sender.ShowCell(l_SelCornerPos); } } } } }