ListBox.SelectedIndexCollection.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System.Collections;
  2. namespace System.Windows.Forms
  3. {
  4. public partial class ListBox
  5. {
  6. public class SelectedIndexCollection : CollectionBase
  7. {
  8. private ListBox owner;
  9. public int this[int index] => (int)List[index];
  10. public void Add(int index)
  11. {
  12. owner.SelectedItems.Add(owner.Items[index]);
  13. }
  14. public void AddInternal(int index)
  15. {
  16. List.Add(index);
  17. }
  18. public void Remove(int index)
  19. {
  20. owner.SelectedItems.Remove(owner.Items[index]);
  21. }
  22. public new void Clear()
  23. {
  24. owner.SelectedItems.Clear();
  25. }
  26. public int IndexOf(int selectedIndex) => List.IndexOf(selectedIndex);
  27. public bool Contains(int selectedIndex) => IndexOf(selectedIndex) != -1;
  28. internal SelectedIndexCollection(ListBox owner) => this.owner = owner;
  29. }
  30. }
  31. }