/// <summary> /// Handle a change row command /// </summary> /// <param name="keyData"></param> /// <param name="behaviour"></param> protected virtual void HandleRowChange(Keys keyData, CellEditCharacterBehaviour behaviour) { // If we couldn't finish editing the current cell, don't try to move it if (!this.ListView.PossibleFinishCellEditing()) { return; } OLVListItem olvi = this.ItemBeingEdited; int subItemIndex = this.SubItemIndexBeingEdited; bool isGoingUp = behaviour == CellEditCharacterBehaviour.ChangeRowUp; // Try to find a row above (or below) the currently edited cell // If we find one, start editing it and we're done. OLVListItem adjacentOlvi = this.GetAdjacentItemOrNull(olvi, isGoingUp); if (adjacentOlvi != null) { this.StartCellEditIfDifferent(adjacentOlvi, subItemIndex); return; } // There is no adjacent row in the direction we want, so we must be on an edge. CellEditAtEdgeBehaviour atEdgeBehaviour = CellEditAtEdgeBehaviour.Wrap; this.CellEditKeyAtEdgeBehaviourMap.TryGetValue(keyData, out atEdgeBehaviour); switch (atEdgeBehaviour) { case CellEditAtEdgeBehaviour.Ignore: break; case CellEditAtEdgeBehaviour.EndEdit: this.ListView.PossibleFinishCellEditing(); break; case CellEditAtEdgeBehaviour.Wrap: adjacentOlvi = this.GetAdjacentItemOrNull(null, isGoingUp); this.StartCellEditIfDifferent(adjacentOlvi, subItemIndex); break; case CellEditAtEdgeBehaviour.ChangeColumn: // Figure out the next editable column List <OLVColumn> editableColumnsInDisplayOrder = this.EditableColumnsInDisplayOrder; int displayIndex = Math.Max(0, editableColumnsInDisplayOrder.IndexOf(this.ListView.GetColumn(subItemIndex))); if (isGoingUp) { displayIndex = (editableColumnsInDisplayOrder.Count + displayIndex - 1) % editableColumnsInDisplayOrder.Count; } else { displayIndex = (displayIndex + 1) % editableColumnsInDisplayOrder.Count; } subItemIndex = editableColumnsInDisplayOrder[displayIndex].Index; // Wrap to the next row and start the cell edit adjacentOlvi = this.GetAdjacentItemOrNull(null, isGoingUp); this.StartCellEditIfDifferent(adjacentOlvi, subItemIndex); break; } }
/// <summary> /// Handle a change column command /// </summary> /// <param name="keyData"></param> /// <param name="behaviour"></param> protected virtual void HandleColumnChange(Keys keyData, CellEditCharacterBehaviour behaviour) { // If we couldn't finish editing the current cell, don't try to move it if (!this.ListView.PossibleFinishCellEditing()) return; // Changing columns only works in details mode if (this.ListView.View != View.Details) return; List<OLVColumn> editableColumns = this.EditableColumnsInDisplayOrder; OLVListItem olvi = this.ItemBeingEdited; int displayIndex = Math.Max(0, editableColumns.IndexOf(this.ListView.GetColumn(this.SubItemIndexBeingEdited))); bool isGoingLeft = behaviour == CellEditCharacterBehaviour.ChangeColumnLeft; // Are we trying to continue past one of the edges? if ((isGoingLeft && displayIndex == 0) || (!isGoingLeft && displayIndex == editableColumns.Count - 1)) { // Yes, so figure out our at edge behaviour CellEditAtEdgeBehaviour atEdgeBehaviour = CellEditAtEdgeBehaviour.Wrap; this.CellEditKeyAtEdgeBehaviourMap.TryGetValue(keyData, out atEdgeBehaviour); switch (atEdgeBehaviour) { case CellEditAtEdgeBehaviour.Ignore: return; case CellEditAtEdgeBehaviour.EndEdit: this.HandleEndEdit(); return; case CellEditAtEdgeBehaviour.ChangeRow: case CellEditAtEdgeBehaviour.Wrap: if (atEdgeBehaviour == CellEditAtEdgeBehaviour.ChangeRow) olvi = GetAdjacentItem(olvi, isGoingLeft && displayIndex == 0); if (isGoingLeft) displayIndex = editableColumns.Count - 1; else displayIndex = 0; break; } } else { if (isGoingLeft) displayIndex -= 1; else displayIndex += 1; } int subItemIndex = editableColumns[displayIndex].Index; this.StartCellEditIfDifferent(olvi, subItemIndex); }
/// <summary> /// Sets the behaviour of a given key /// </summary> /// <param name="key"></param> /// <param name="normalBehaviour"></param> /// <param name="atEdgeBehaviour"></param> public virtual void SetKeyBehaviour(Keys key, CellEditCharacterBehaviour normalBehaviour, CellEditAtEdgeBehaviour atEdgeBehaviour) { this.CellEditKeyMap[key] = normalBehaviour; this.CellEditKeyAtEdgeBehaviourMap[key] = atEdgeBehaviour; }