private void UpdateSelection(byte idx) { if (PalSource == null) return; if (ModifierKeys == Keys.Alt) { BackColor = PalSource[idx]; BackColorChanged?.Invoke(this, new EventArgs()); return; } if (!IsSelectable) return; if (IsMultiSelect) { switch (ModifierKeys) { case Keys.Control: if (Selections.Contains(idx)) Selections.Remove(idx); else Selections.Add(idx); break; case Keys.Shift: if (Selections.Count == 0) { Selections.Add(idx); break; } if (Selections.Last() == idx) { Selections.Remove(idx); } else { if (Selections.Last() < idx) { for (int i = Selections.Last() + 1; i <= idx; i++) if (!Selections.Contains((byte)i)) Selections.Add((byte)i); } else { for (int i = Selections.Last() - 1; i >= idx; i--) if (!Selections.Contains((byte)i)) Selections.Add((byte)i); } } break; default: Selections.Clear(); Selections.Add(idx); break; } } else { Selections.Clear(); Selections.Add(idx); } if (PalSource != null) SelectedIndexChanged?.Invoke(this, new EventArgs()); if (IsSelectVisible) Refresh(); }
public void DeleteCurrentSelection() { Selections.Remove(CurrentSelection); CurrentSelection = Selections.FirstOrDefault(); if (!Selections.Contains(_currentlySaved)) { _currentlySaved = null; } SaveSelection(); }
public void SelectionCheckBox_Init(object sender, EventArgs e) { try { CheckBox rowCheckBox = (CheckBox)sender; rowCheckBox.Checked = Selections.Contains(GetDataKeyObject(rowCheckBox)); } catch (Exception ex) { Util.Log.Error("DridViewEx::SelectionCheckBox_Init", ex); } }
protected override bool IsInputKey(Keys keyData) { if (PalSource == null) return false; Cursor = Cursors.Default; byte idx = Selections.LastOrDefault(); int curX = idx / 32; int curY = idx % 32; switch (keyData) { // Functional Keys case Keys.Control: case Keys.Shift: case Keys.Alt: return true; // Move Idx case Keys.Up: if (curY > 0) UpdateSelection((byte)(idx - 1)); else if (curX > 0) UpdateSelection((byte)(idx - 1)); return true; case Keys.Down: if (curY < 31) UpdateSelection((byte)(idx + 1)); else if (curX < 7) UpdateSelection((byte)(idx + 1)); return true; case Keys.Left: if (curX > 0) UpdateSelection((byte)(idx - 32)); return true; case Keys.Right: if (curX < 7) UpdateSelection((byte)(idx + 32)); return true; case Keys.Delete: if (IsEditable) { PalSourceChanging?.Invoke(this, new EventArgs()); if (!Selections.Contains(idx)) Selections.Add(idx); foreach (byte i in Selections) PalSource[i] = BackColor; PalSourceChanged?.Invoke(this, new EventArgs()); } return true; } return false; }
/// <summary> /// Handles the CheckedChanged event of the SelectionCheckBox control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> public void SelectionCheckBox_CheckedChanged(object sender, EventArgs e) { try { var rowCheckBox = (CheckBox)sender; var key = GetDataKeyObject(rowCheckBox); var inSelection = Selections.Contains(key); if (rowCheckBox.Checked && !inSelection) { Selections.Add(key); } else if (!rowCheckBox.Checked && inSelection) { Selections.Remove(key); } } catch (Exception ex) { Util.Log.Error("DridViewEx::SelectionCheckBox_CheckedChanged", ex); } }