public void SelectItems(int startRange, int endRange) { _selectedIndices.Clear(); if (startRange == endRange) { _selectedIndices.Add(startRange); } if (startRange < endRange) { for (var i = startRange; i <= endRange; i++) { _selectedIndices.Add(i); } } else if (startRange > endRange) { for (var i = startRange; i >= endRange; i--) { _selectedIndices.Add(i); } } SelectedIndicesChanged?.Invoke(this, null); Invalidate(); }
public void ClearSelection() { _selectedIndices.Clear(); Invalidate(); SelectedIndicesChanged?.Invoke(this, null); _anchoredItemStart = -1; _anchoredItemEnd = -1; }
private void Items_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (e.NewItems != null) { using (var g = CreateGraphics()) { // Set the area size of all new items foreach (DarkListItem item in e.NewItems) { item.TextChanged += Item_TextChanged; UpdateItemSize(item, g); } } // Find the starting index of the new item list and update anything past that if (e.NewStartingIndex < Items.Count - 1) { for (var i = e.NewStartingIndex; i <= Items.Count - 1; i++) { UpdateItemPosition(Items[i], i); } } } if (e.OldItems != null) { foreach (DarkListItem item in e.OldItems) { item.TextChanged -= Item_TextChanged; } // Find the starting index of the old item list and update anything past that if (e.OldStartingIndex < Items.Count - 1) { for (var i = e.OldStartingIndex; i <= Items.Count - 1; i++) { UpdateItemPosition(Items[i], i); } } } if (Items.Count == 0) { if (_selectedIndices.Count > 0) { _selectedIndices.Clear(); SelectedIndicesChanged?.Invoke(this, null); } } UpdateContentSize(); }
public void SelectItem(int index) { if (index < 0 || index > Items.Count - 1) { throw new IndexOutOfRangeException($"Value '{index}' is outside of valid range."); } _selectedIndices.Clear(); _selectedIndices.Add(index); SelectedIndicesChanged?.Invoke(this, null); _anchoredItemStart = index; _anchoredItemEnd = index; Invalidate(); }
public void SelectItems(IEnumerable <int> indexes) { _selectedIndices.Clear(); var list = indexes.ToList(); foreach (var index in list) { if (index < 0 || index > Items?.Count - 1) { throw new IndexOutOfRangeException($"Value '{index}' is outside of valid range."); } _selectedIndices.Add(index); } SelectedIndicesChanged?.Invoke(this, EventArgs.Empty); _anchoredItemStart = list[^ 1];
public void ToggleItem(int index) { if (_selectedIndices.Contains(index)) { _selectedIndices.Remove(index); // If we just removed both the anchor start AND end then reset them if (_anchoredItemStart == index && _anchoredItemEnd == index) { if (_selectedIndices.Count > 0) { _anchoredItemStart = _selectedIndices[0]; _anchoredItemEnd = _selectedIndices[0]; } else { _anchoredItemStart = -1; _anchoredItemEnd = -1; } } // If we just removed the anchor start then update it accordingly if (_anchoredItemStart == index) { if (_anchoredItemEnd < index) { _anchoredItemStart = index - 1; } else if (_anchoredItemEnd > index) { _anchoredItemStart = index + 1; } else { _anchoredItemStart = _anchoredItemEnd; } } // If we just removed the anchor end then update it accordingly if (_anchoredItemEnd == index) { if (_anchoredItemStart < index) { _anchoredItemEnd = index - 1; } else if (_anchoredItemStart > index) { _anchoredItemEnd = index + 1; } else { _anchoredItemEnd = _anchoredItemStart; } } } else { _selectedIndices.Add(index); _anchoredItemStart = index; _anchoredItemEnd = index; } SelectedIndicesChanged?.Invoke(this, null); Invalidate(); }