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; }
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; } } } }