public void AddItem(int _SortValue, Image _LeftSideImage, string _Title, string _Description, string _Authors, DetailedListItem.RightSide _RightSide = null) { DetailedListItem newListItem = new DetailedListItem(); newListItem.Name = "item" + UniqueIDCounter++; newListItem.Margin = new Padding(0); newListItem.Title = _Title; newListItem.Description = _Description; newListItem.Authors = _Authors; newListItem.Image = _LeftSideImage; newListItem._SetSortValue(int.MinValue); if (_RightSide != null) { newListItem.SetRightSideControls(_RightSide); } if (flpListBox.Controls.Count == 0) { flpListBox.Controls.Add(newListItem); newListItem._SetSortValue(_SortValue); SetupAnchors(); } else { newListItem.Anchor = AnchorStyles.Left | AnchorStyles.Right; flpListBox.Controls.Add(newListItem); SetSortValue(newListItem, _SortValue); } newListItem.EventSelectChanged += Item_SelectionChanged; newListItem.MouseEnter += flpListBox_MouseEnter; }
private void Item_SelectionChanged(DetailedListItem _ListItem) { if (_ListItem.Selected == true) { int newSelectIndex = flpListBox.Controls.IndexOf(_ListItem); if (m_CurrentSelected != null) { int prevSelectIndex = flpListBox.Controls.IndexOf(m_CurrentSelected); m_CurrentSelected.Selected = false; if (newSelectIndex < prevSelectIndex) { for (int i = newSelectIndex + 1; i < flpListBox.Controls.Count; i++) { var currItem = (DetailedListItem)flpListBox.Controls[i]; currItem.Expanded = false; } } } m_CurrentSelected = _ListItem; _ListItem.Expanded = true; if (EventItemSelected != null) { EventItemSelected(newSelectIndex); } } }
public void Clear() { while (flpListBox.Controls.Count != 0) { DetailedListItem item = (DetailedListItem)flpListBox.Controls[0]; flpListBox.Controls.Remove(item); // remove the event hook item.EventSelectChanged -= Item_SelectionChanged; item.MouseEnter -= flpListBox_MouseEnter; item.Dispose(); } m_CurrentSelected = null; }
public void RemoveItem(int _Index) { DetailedListItem item = (DetailedListItem)flpListBox.Controls[_Index]; int prevTop = item.Top;// int.MaxValue; DetailedListItem newSelected = null; item.tmrMouseLeave.Stop(); item.EventSelectChanged -= Item_SelectionChanged; item.MouseEnter -= flpListBox_MouseEnter; if (item.Selected == true) { if (flpListBox.Controls.Count > _Index + 1) { newSelected = ((DetailedListItem)flpListBox.Controls[_Index + 1]); newSelected.Selected = true; } else if (_Index - 1 >= 0) { newSelected = ((DetailedListItem)flpListBox.Controls[_Index - 1]); newSelected.Selected = true; } } if (_Index == 0 && flpListBox.Controls.Count > 1) { flpListBox.Controls[1].Anchor = AnchorStyles.Left | AnchorStyles.Top; flpListBox.Controls[1].Width = flpListBox.Width - (flpListBox.VerticalScroll.Visible == true ? SystemInformation.VerticalScrollBarWidth : 0); } flpListBox.Controls.Remove(item); item.Dispose(); if (newSelected != null) { int deltaMove = newSelected.Top - prevTop; int newScrollValue = flpListBox.VerticalScroll.Value + deltaMove; if (newScrollValue > flpListBox.VerticalScroll.Maximum) { newScrollValue = flpListBox.VerticalScroll.Maximum; } if (newScrollValue < flpListBox.VerticalScroll.Minimum) { newScrollValue = flpListBox.VerticalScroll.Minimum; } flpListBox.VerticalScroll.Value = newScrollValue; flpListBox.PerformLayout(); } }
public void SetSortValue(DetailedListItem _Item, int _SortValue) { if (_Item.SortValue == _SortValue) { return; } int prevIndex = int.MaxValue; _Item._SetSortValue(_SortValue); if (flpListBox.Controls.Count > 1) { for (int i = 0; i < flpListBox.Controls.Count; ++i) { var currItem = (DetailedListItem)flpListBox.Controls[i]; if (currItem == _Item) { prevIndex = i; } else if (currItem.SortValue < _SortValue) { if (i - 1 == prevIndex) //>= 0 && (DetailedListItem)flpListBox.Controls[i - 1] == _Item) { break; //Redan på rätt plats } if (prevIndex != int.MaxValue && i > 0) { i = i - 1; } flpListBox.Controls.SetChildIndex(_Item, i); if (prevIndex == 0) { flpListBox.Controls[0].Anchor = AnchorStyles.Left | AnchorStyles.Top; flpListBox.Controls[0].Width = flpListBox.Width - (flpListBox.VerticalScroll.Visible == true ? SystemInformation.VerticalScrollBarWidth : 0); _Item.Anchor = AnchorStyles.Left | AnchorStyles.Right; } else if (i == 0) { _Item.Anchor = AnchorStyles.Left | AnchorStyles.Top; _Item.Width = flpListBox.Width - (flpListBox.VerticalScroll.Visible == true ? SystemInformation.VerticalScrollBarWidth : 0); flpListBox.Controls[1].Anchor = AnchorStyles.Left | AnchorStyles.Right; } break; } } } }
public void RemoveItem(DetailedListItem _Item) { for (int i = 0; i < flpListBox.Controls.Count; ++i) { if (((DetailedListItem)flpListBox.Controls[i]) == _Item) { RemoveItem(i); return; } } throw new Exception("Could not RemoveItem" + _Item.Name); //_Item.tmrMouseLeave.Stop(); //_Item.EventSelectChanged -= Item_SelectionChanged; //_Item.MouseEnter -= flpListBox_MouseEnter; //flpListBox.Controls.Remove(_Item); //_Item.Dispose(); //SetupAnchors(); }
public void RemoveItem(string name) { DetailedListItem item = (DetailedListItem)flpListBox.Controls[name]; RemoveItem(item); }
public void SetSortValue(int _Index, int _SortValue) { DetailedListItem item = (DetailedListItem)flpListBox.Controls[_Index]; SetSortValue(item, _SortValue); }
public void _SetDetailedListItem(DetailedListItem _ListItem) { m_ListItem = _ListItem; }