Virtual Collapsable Cell
Represents an expand - collapse cell, useful to display parent-child records.
Namespace: LSOne.Controls.Cells
Assembly: LSOne.Controls.ListView
Syntax
public class VirtualCollapsableCell : ExtendedCell
Constructors
Name | Description |
---|---|
VirtualCollapsableCell() | Default constructor. Initializes a new instance of the VirtualCollapsableCell class |
VirtualCollapsableCell(bool) | Initializes a new instance of the VirtualCollapsableCell class with the given collapsed state. |
VirtualCollapsableCell(string, bool) | Initializes a new instance of the VirtualCollapsableCell class with the given text and collapsed state. |
VirtualCollapsableCell(string, System.Drawing.Image, bool) | Initializes a new instance of the VirtualCollapsableCell class with the given text, image and collapsed state. |
Properties
Name | Description |
---|---|
Collapsed | Gets the collapsed state |
Hover | Gets or sets if mouse hovers over the cell |
PartSize | Gets or sets the size of the current visual style (System.Windows.Forms.VisualStyles.ThemeSizeType.Draw ) |
Methods
Name | Description |
---|---|
SetCollapsed(LSOne.Controls.ListView, int, bool) | If value is true then all child rows belonging to the given rowNumber of the given listView are collapsedÈ™ otherwise they're expanded. |
Remarks
Base class for:
To display parent-child records in a List View you need to:
- add parent rows to the list view plus the column that will contain the collapsable cell
- implement handler for ListView.RowExpanded event where the child rows are added to the list view
- implement handler for ListView.RowCollapsed event where the child rows are removed from the list view
Examples
See Source\SM\Plugins\RetailItems\Views\ItemsView.cs from DevPack for usage examples.
private void LoadItems()
{
lvItems.ClearRows();
int itemsCount = 0;
items = service.GetParentItems();
Row row;
foreach (Item item in items)
{
row = new Row();
row.AddCell(new VirtualCollapsableCell((string)item.ID, true));
row.AddText(item.ItemName);
row.Tag = item;
lvItems.AddRow(row);
}
}
public void LoadData(bool isRevert, RecordIdentifier context, object internalContext)
{
LoadItems();
}
private void lvItems_RowExpanded(object sender, RowEventArgs args)
{
Item parentItem = (Item)lvItems.Row(args.RowNumber).Tag;
List<Item> subRows = service.GetChildItems();
int nextRowNumber = args.RowNumber + 1;
foreach (Item item in subRows)
{
Row row = new Row();
row.AddCell(new ExtendedCell(string.Empty));
row.AddText((string)item.ItemId);
row.AddText(item.ItemName);
row.Tag = item;
lvItems.InsertRow(nextRowNumber, row);
items.Insert(nextRowNumber, item);
nextRowNumber++;
}
lvItems.AutoSizeColumns();
}
private void lvItems_RowCollapsed(object sender, RowEventArgs args)
{
Item parentItem = (Item)lvItems.Row(args.RowNumber).Tag;
int rowIndex = args.RowNumber + 1;
while (rowIndex < lvItems.RowCount && parentItem.MasterID == ((Item)lvItems.Row(rowIndex).Tag).ParentMasterID)
{
lvItems.RemoveRow(rowIndex);
items.RemoveAt(rowIndex);
}
lvItems.AutoSizeColumns();
}