/// <summary> /// Raises the BeginEditing event /// </summary> /// <param name="e">A CellEditEventArgs that contains the event data</param> protected internal virtual void OnBeginEditing(CellEditEventArgs e) { if (this.CanRaiseEvents) { if (BeginEditing != null) { BeginEditing(e.Cell, e); } } }
/// <summary> /// Raises the EditingStopped event /// </summary> /// <param name="e">A CellEditEventArgs that contains the event data</param> protected internal virtual void OnEditingStopped(CellEditEventArgs e) { if (this.CanRaiseEvents) { if (EditingStopped != null) { EditingStopped(e.Cell, e); } } }
/// <summary> /// Starts editing the Cell at the specified CellPos /// </summary> /// <param name="cellPos">A CellPos that specifies the Cell to be edited</param> public void EditCell(CellPos cellPos) { // don't bother if the cell doesn't exists or the cell's // column is not visible or the cell is not editable if (!this.IsValidCell(cellPos) || !this.ColumnModel.Columns[cellPos.Column].Visible || !this.IsCellEditable(cellPos)) { return; } // check if we're currently editing a cell if (this.EditingCell != CellPos.Empty) { // don't bother if we're already editing the cell. // if we're editing a different cell stop editing if (this.EditingCell == cellPos) { return; } else { this.EditingCellEditor.StopEditing(); } } Cell cell = this.TableModel[cellPos]; ICellEditor editor = this.ColumnModel.GetCellEditor(cellPos.Column); // make sure we have an editor and that the cell // and the cell's column are editable if (editor == null || !cell.Editable || !this.ColumnModel.Columns[cellPos.Column].Editable) { return; } if (this.EnsureVisible(cellPos)) { this.Refresh(); } Rectangle cellRect = this.CellRect(cellPos); // give anyone subscribed to the table's BeginEditing // event the first chance to cancel editing CellEditEventArgs e = new CellEditEventArgs(cell, editor, this, cellPos.Row, cellPos.Column, cellRect); this.OnBeginEditing(e); // if (!e.Cancel) { // get the editor ready for editing. if PrepareForEditing // returns false, someone who subscribed to the editors // BeginEdit event has cancelled editing if (!editor.PrepareForEditing(cell, this, cellPos, cellRect, e.Handled)) { return; } // keep track of the editing cell and editor // and start editing this.editingCell = cellPos; this.curentCellEditor = editor; editor.StartEditing(); } }
/// <summary> /// Raises the EndEdit event /// </summary> /// <param name="e">A CellEditEventArgs that contains the event data</param> protected virtual void OnEndEdit(CellEditEventArgs e) { if (this.EndEdit != null) { this.EndEdit(this, e); } }
/// <summary> /// Stops editing the Cell and commits any changes /// </summary> public virtual void StopEditing() { Application.RemoveMessageFilter(this.keyMessageFilter); Application.RemoveMessageFilter(this.mouseMessageFilter); // CellEditEventArgs e = new CellEditEventArgs(this.cell, this, this.table, this.cellPos.Row, this.cellPos.Column, this.cellRect); this.table.OnEditingStopped(e); this.OnEndEdit(e); if (!e.Cancel && !e.Handled) { this.SetCellValue(); } this.RemoveEditControl(); }
/// <summary> /// Prepares the CellEditor to edit the specified Cell /// </summary> /// <param name="cell">The Cell to be edited</param> /// <param name="table">The Table that contains the Cell</param> /// <param name="cellPos">A CellPos representing the position of the Cell</param> /// <param name="cellRect">The Rectangle that represents the Cells location and size</param> /// <param name="userSetEditorValues">Specifies whether the ICellEditors /// starting value has already been set by the user</param> /// <returns>true if the ICellEditor can continue editing the Cell, false otherwise</returns> public virtual bool PrepareForEditing(Cell cell, Table table, CellPos cellPos, Rectangle cellRect, bool userSetEditorValues) { // this.cell = cell; this.table = table; this.cellPos = cellPos; this.cellRect = cellRect; // check if the user has already set the editors value for us if (!userSetEditorValues) { this.SetEditValue(); } this.SetEditLocation(cellRect); // raise the BeginEdit event CellEditEventArgs e = new CellEditEventArgs(cell, this, table, cellPos.Row, cellPos.Column, cellRect); e.Handled = userSetEditorValues; this.OnBeginEdit(e); // if the edit has been canceled, remove the editor and return false if (e.Cancel) { this.RemoveEditControl(); return false; } return true; }
/// <summary> /// Stops editing the Cell and ignores any changes /// </summary> public virtual void CancelEditing() { Application.RemoveMessageFilter(this.keyMessageFilter); Application.RemoveMessageFilter(this.mouseMessageFilter); // CellEditEventArgs e = new CellEditEventArgs(this.cell, this, this.table, this.cellPos.Row, this.cellPos.Column, this.cellRect); this.table.OnEditingCancelled(e); this.OnCancelEdit(e); this.RemoveEditControl(); }