C# Class BrightIdeasSoftware.VirtualObjectListView

A virtual object list view operates in virtual mode, that is, it only gets model objects for a row when it is needed. This gives it the ability to handle very large numbers of rows with minimal resources.

A listview is not a great user interface for a large number of items. But if you've ever wanted to have a list with 10 million items, go ahead, knock yourself out.

Virtual lists can never iterate their contents. That would defeat the whole purpose.

Animated GIFs should not be used in virtual lists. Animated GIFs require some state information to be stored for each animation, but virtual lists specifically do not keep any state information. In any case, you really do not want to keep state information for 10 million animations!

Although it isn't documented, .NET virtual lists cannot have checkboxes. This class codes around this limitation, but you must use the functions provided by ObjectListView: CheckedObjects, CheckObject(), UncheckObject() and their friends. If you use the normal check box properties (CheckedItems or CheckedIndicies), they will throw an exception, since the list is in virtual mode, and .NET "knows" it can't handle checkboxes in virtual mode.

Due to the limits of the underlying Windows control, virtual lists do not trigger ItemCheck/ItemChecked events. Use a CheckStatePutter instead.

To enable grouping, you must provide an implmentation of IVirtualGroups interface, via the GroupingStrategy property.

Similarly, to enable filtering on the list, your VirtualListDataSource must also implement the IFilterableDataSource interface.

Inheritance: ObjectListView
Afficher le fichier Open project: soywiz/cspspemu Class Usage Examples

Private Properties

Свойство Type Description

Méthodes publiques

Méthode Description
AddObjects ( ICollection modelObjects ) : void

Add the given collection of model objects to this control.

The added objects will appear in their correct sort position, if sorting is active. Otherwise, they will appear at the end of the list.

No check is performed to see if any of the objects are already in the ListView.

Null objects are silently ignored.

BuildList ( bool shouldPreserveSelection ) : void

Rebuild the list with its current contents.

Invalidate any cached information when we rebuild the list.

ClearCachedInfo ( ) : void

Clear any cached info this list may have been using

ClearObjects ( ) : void

Remove all items from this list

EnsureNthGroupVisible ( int groupIndex ) : void

Scroll the listview so that the given group is at the top.

If the group is already visible, the list will still be scrolled to move the group to the top, if that is possible.

This only works when the list is showing groups (obviously).

GetDisplayOrderOfItemIndex ( int itemIndex ) : int

Return the position of the given itemIndex in the list as it currently shown to the user. If the control is not grouped, the display order is the same as the sorted list order. But if the list is grouped, the display order is different.

GetItemCount ( ) : int

Return the number of items in the list

GetLastItemInDisplayOrder ( ) : BrightIdeasSoftware.OLVListItem

Return the last item in the order they are shown to the user. If the control is not grouped, the display order is the same as the sorted list order. But if the list is grouped, the display order is different.

GetModelObject ( int index ) : object

Return the model object at the given index

GetNextItem ( BrightIdeasSoftware.OLVListItem itemToFind ) : BrightIdeasSoftware.OLVListItem

Return the ListViewItem that appears immediately after the given item. If the given item is null, the first item in the list will be returned. Return null if the given item is the last item.

GetNthItemInDisplayOrder ( int n ) : BrightIdeasSoftware.OLVListItem

Return the n'th item (0-based) in the order they are shown to the user. If the control is not grouped, the display order is the same as the sorted list order. But if the list is grouped, the display order is different.

GetPreviousItem ( BrightIdeasSoftware.OLVListItem itemToFind ) : BrightIdeasSoftware.OLVListItem

Return the ListViewItem that appears immediately before the given item. If the given item is null, the last item in the list will be returned. Return null if the given item is the first item.

IndexOf ( Object modelObject ) : int

Find the given model object within the listview and return its index

MakeListViewItem ( int itemIndex ) : BrightIdeasSoftware.OLVListItem

Create a OLVListItem for given row index

ModelToItem ( object modelObject ) : BrightIdeasSoftware.OLVListItem

Return the OLVListItem that displays the given model object

This method has O(n) performance.

RefreshItem ( BrightIdeasSoftware.OLVListItem olvi ) : void

Refresh the given item in the list

RefreshObjects ( IList modelObjects ) : void

Update the rows that are showing the given objects

This method does not resort the items.

RefreshSelectedObjects ( ) : void

Update the rows that are selected

This method does not resort or regroup the view.

RemoveObjects ( ICollection modelObjects ) : void

Remove all of the given objects from the control

Nulls and model objects that are not in the ListView are silently ignored.

Due to problems in the underlying ListView, if you remove all the objects from the control using this method and the list scroll vertically when you do so, then when you subsequenially add more objects to the control, the vertical scroll bar will become confused and the control will draw one or more blank lines at the top of the list.

SelectObject ( object modelObject, bool setFocus ) : void

Select the row that is displaying the given model object. All other rows are deselected.

SelectObjects ( IList modelObjects ) : void

Select the rows that is displaying any of the given model object. All other rows are deselected.

This method has O(n) performance where n is the number of model objects passed. Do not use this to select all the rows in the list -- use SelectAll() for that.

SetObjects ( IEnumerable collection, bool preserveState ) : void

Set the collection of objects that this control will show.

UpdateVirtualListSize ( ) : void

Change the size of the virtual list so that it matches its data source

VirtualObjectListView ( ) : System

Create a VirtualObjectListView

Méthodes protégées

Méthode Description
CreateGroups ( IEnumerable groups ) : void

Do the work of creating groups for this control

DisableVirtualGroups ( ) : void

Do the plumbing to disable groups on a virtual list

EnableVirtualGroups ( ) : void

Do the plumbing to enable groups on a virtual list

FindMatchInRange ( string text, int first, int last, OLVColumn column ) : int

Find the first row in the given range of rows that prefix matches the string value of the given column.

GetCheckState ( object modelObject ) : CheckState?

Get the checkedness of an object from the model. Returning null means the model does know and the value from the control will be used.

HandleCacheVirtualItems ( object sender, System.Windows.Forms.CacheVirtualItemsEventArgs e ) : void

Handle the CacheVirtualItems event

HandleRetrieveVirtualItem ( object sender, System.Windows.Forms.RetrieveVirtualItemEventArgs e ) : void

Handle a RetrieveVirtualItem

HandleSearchForVirtualItem ( object sender, System.Windows.Forms.SearchForVirtualItemEventArgs e ) : void

Handle the SearchForVirtualList event, which is called when the user types into a virtual list

MakeGroups ( BrightIdeasSoftware.GroupingParameters parms ) : IList

Make a list of groups that should be shown according to the given parameters

PostProcessRows ( ) : void

On virtual lists, this cannot work.

PutCheckState ( object modelObject, CheckState state ) : CheckState

Record the change of checkstate for the given object in the model. This does not update the UI -- only the model

SetVirtualListSize ( int newSize ) : void

Change the size of the list

TakeOwnershipOfObjects ( ) : void

Take ownership of the 'objects' collection. This separates our collection from the source.

This method separates the 'objects' instance variable from its source, so that any AddObject/RemoveObject calls will modify our collection and not the original colleciton.

VirtualObjectListViews always own their collections, so this is a no-op.

UpdateFiltering ( ) : void

Change the state of the control to reflect changes in filtering

Method Details

AddObjects() public méthode

Add the given collection of model objects to this control.

The added objects will appear in their correct sort position, if sorting is active. Otherwise, they will appear at the end of the list.

No check is performed to see if any of the objects are already in the ListView.

Null objects are silently ignored.

public AddObjects ( ICollection modelObjects ) : void
modelObjects ICollection A collection of model objects
Résultat void

BuildList() public méthode

Rebuild the list with its current contents.
Invalidate any cached information when we rebuild the list.
public BuildList ( bool shouldPreserveSelection ) : void
shouldPreserveSelection bool
Résultat void

ClearCachedInfo() public méthode

Clear any cached info this list may have been using
public ClearCachedInfo ( ) : void
Résultat void

ClearObjects() public méthode

Remove all items from this list
public ClearObjects ( ) : void
Résultat void

CreateGroups() protected méthode

Do the work of creating groups for this control
protected CreateGroups ( IEnumerable groups ) : void
groups IEnumerable
Résultat void

DisableVirtualGroups() protected méthode

Do the plumbing to disable groups on a virtual list
protected DisableVirtualGroups ( ) : void
Résultat void

EnableVirtualGroups() protected méthode

Do the plumbing to enable groups on a virtual list
protected EnableVirtualGroups ( ) : void
Résultat void

EnsureNthGroupVisible() public méthode

Scroll the listview so that the given group is at the top.

If the group is already visible, the list will still be scrolled to move the group to the top, if that is possible.

This only works when the list is showing groups (obviously).

public EnsureNthGroupVisible ( int groupIndex ) : void
groupIndex int The index of the group to be revealed
Résultat void

FindMatchInRange() protected méthode

Find the first row in the given range of rows that prefix matches the string value of the given column.
protected FindMatchInRange ( string text, int first, int last, OLVColumn column ) : int
text string
first int
last int
column OLVColumn
Résultat int

GetCheckState() protected méthode

Get the checkedness of an object from the model. Returning null means the model does know and the value from the control will be used.
protected GetCheckState ( object modelObject ) : CheckState?
modelObject object
Résultat CheckState?

GetDisplayOrderOfItemIndex() public méthode

Return the position of the given itemIndex in the list as it currently shown to the user. If the control is not grouped, the display order is the same as the sorted list order. But if the list is grouped, the display order is different.
public GetDisplayOrderOfItemIndex ( int itemIndex ) : int
itemIndex int
Résultat int

GetItemCount() public méthode

Return the number of items in the list
public GetItemCount ( ) : int
Résultat int

GetLastItemInDisplayOrder() public méthode

Return the last item in the order they are shown to the user. If the control is not grouped, the display order is the same as the sorted list order. But if the list is grouped, the display order is different.
public GetLastItemInDisplayOrder ( ) : BrightIdeasSoftware.OLVListItem
Résultat BrightIdeasSoftware.OLVListItem

GetModelObject() public méthode

Return the model object at the given index
public GetModelObject ( int index ) : object
index int Index of the model object to be returned
Résultat object

GetNextItem() public méthode

Return the ListViewItem that appears immediately after the given item. If the given item is null, the first item in the list will be returned. Return null if the given item is the last item.
public GetNextItem ( BrightIdeasSoftware.OLVListItem itemToFind ) : BrightIdeasSoftware.OLVListItem
itemToFind BrightIdeasSoftware.OLVListItem The item that is before the item that is returned, or null
Résultat BrightIdeasSoftware.OLVListItem

GetNthItemInDisplayOrder() public méthode

Return the n'th item (0-based) in the order they are shown to the user. If the control is not grouped, the display order is the same as the sorted list order. But if the list is grouped, the display order is different.
public GetNthItemInDisplayOrder ( int n ) : BrightIdeasSoftware.OLVListItem
n int
Résultat BrightIdeasSoftware.OLVListItem

GetPreviousItem() public méthode

Return the ListViewItem that appears immediately before the given item. If the given item is null, the last item in the list will be returned. Return null if the given item is the first item.
public GetPreviousItem ( BrightIdeasSoftware.OLVListItem itemToFind ) : BrightIdeasSoftware.OLVListItem
itemToFind BrightIdeasSoftware.OLVListItem The item that is before the item that is returned
Résultat BrightIdeasSoftware.OLVListItem

HandleCacheVirtualItems() protected méthode

Handle the CacheVirtualItems event
protected HandleCacheVirtualItems ( object sender, System.Windows.Forms.CacheVirtualItemsEventArgs e ) : void
sender object
e System.Windows.Forms.CacheVirtualItemsEventArgs
Résultat void

HandleRetrieveVirtualItem() protected méthode

Handle a RetrieveVirtualItem
protected HandleRetrieveVirtualItem ( object sender, System.Windows.Forms.RetrieveVirtualItemEventArgs e ) : void
sender object
e System.Windows.Forms.RetrieveVirtualItemEventArgs
Résultat void

HandleSearchForVirtualItem() protected méthode

Handle the SearchForVirtualList event, which is called when the user types into a virtual list
protected HandleSearchForVirtualItem ( object sender, System.Windows.Forms.SearchForVirtualItemEventArgs e ) : void
sender object
e System.Windows.Forms.SearchForVirtualItemEventArgs
Résultat void

IndexOf() public méthode

Find the given model object within the listview and return its index
public IndexOf ( Object modelObject ) : int
modelObject Object The model object to be found
Résultat int

MakeGroups() protected méthode

Make a list of groups that should be shown according to the given parameters
protected MakeGroups ( BrightIdeasSoftware.GroupingParameters parms ) : IList
parms BrightIdeasSoftware.GroupingParameters
Résultat IList

MakeListViewItem() public méthode

Create a OLVListItem for given row index
public MakeListViewItem ( int itemIndex ) : BrightIdeasSoftware.OLVListItem
itemIndex int The index of the row that is needed
Résultat BrightIdeasSoftware.OLVListItem

ModelToItem() public méthode

Return the OLVListItem that displays the given model object
This method has O(n) performance.
public ModelToItem ( object modelObject ) : BrightIdeasSoftware.OLVListItem
modelObject object The modelObject whose item is to be found
Résultat BrightIdeasSoftware.OLVListItem

PostProcessRows() protected méthode

On virtual lists, this cannot work.
protected PostProcessRows ( ) : void
Résultat void

PutCheckState() protected méthode

Record the change of checkstate for the given object in the model. This does not update the UI -- only the model
protected PutCheckState ( object modelObject, CheckState state ) : CheckState
modelObject object
state CheckState
Résultat CheckState

RefreshItem() public méthode

Refresh the given item in the list
public RefreshItem ( BrightIdeasSoftware.OLVListItem olvi ) : void
olvi BrightIdeasSoftware.OLVListItem The item to refresh
Résultat void

RefreshObjects() public méthode

Update the rows that are showing the given objects
This method does not resort the items.
public RefreshObjects ( IList modelObjects ) : void
modelObjects IList
Résultat void

RefreshSelectedObjects() public méthode

Update the rows that are selected
This method does not resort or regroup the view.
public RefreshSelectedObjects ( ) : void
Résultat void

RemoveObjects() public méthode

Remove all of the given objects from the control

Nulls and model objects that are not in the ListView are silently ignored.

Due to problems in the underlying ListView, if you remove all the objects from the control using this method and the list scroll vertically when you do so, then when you subsequenially add more objects to the control, the vertical scroll bar will become confused and the control will draw one or more blank lines at the top of the list.

public RemoveObjects ( ICollection modelObjects ) : void
modelObjects ICollection Collection of objects to be removed
Résultat void

SelectObject() public méthode

Select the row that is displaying the given model object. All other rows are deselected.
public SelectObject ( object modelObject, bool setFocus ) : void
modelObject object Model object to select
setFocus bool Should the object be focused as well?
Résultat void

SelectObjects() public méthode

Select the rows that is displaying any of the given model object. All other rows are deselected.
This method has O(n) performance where n is the number of model objects passed. Do not use this to select all the rows in the list -- use SelectAll() for that.
public SelectObjects ( IList modelObjects ) : void
modelObjects IList A collection of model objects
Résultat void

SetObjects() public méthode

Set the collection of objects that this control will show.
public SetObjects ( IEnumerable collection, bool preserveState ) : void
collection IEnumerable
preserveState bool Should the state of the list be preserved as far as is possible.
Résultat void

SetVirtualListSize() protected méthode

Change the size of the list
protected SetVirtualListSize ( int newSize ) : void
newSize int
Résultat void

TakeOwnershipOfObjects() protected méthode

Take ownership of the 'objects' collection. This separates our collection from the source.

This method separates the 'objects' instance variable from its source, so that any AddObject/RemoveObject calls will modify our collection and not the original colleciton.

VirtualObjectListViews always own their collections, so this is a no-op.

protected TakeOwnershipOfObjects ( ) : void
Résultat void

UpdateFiltering() protected méthode

Change the state of the control to reflect changes in filtering
protected UpdateFiltering ( ) : void
Résultat void

UpdateVirtualListSize() public méthode

Change the size of the virtual list so that it matches its data source
public UpdateVirtualListSize ( ) : void
Résultat void

VirtualObjectListView() public méthode

Create a VirtualObjectListView
public VirtualObjectListView ( ) : System
Résultat System