C# Класс 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.

Наследование: ObjectListView
Показать файл Открыть проект Примеры использования класса

Private Properties

Свойство Тип Описание

Открытые методы

Метод Описание
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

Защищенные методы

Метод Описание
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

Описание методов

AddObjects() публичный Метод

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
Результат void

BuildList() публичный Метод

Rebuild the list with its current contents.
Invalidate any cached information when we rebuild the list.
public BuildList ( bool shouldPreserveSelection ) : void
shouldPreserveSelection bool
Результат void

ClearCachedInfo() публичный Метод

Clear any cached info this list may have been using
public ClearCachedInfo ( ) : void
Результат void

ClearObjects() публичный Метод

Remove all items from this list
public ClearObjects ( ) : void
Результат void

CreateGroups() защищенный Метод

Do the work of creating groups for this control
protected CreateGroups ( IEnumerable groups ) : void
groups IEnumerable
Результат void

DisableVirtualGroups() защищенный Метод

Do the plumbing to disable groups on a virtual list
protected DisableVirtualGroups ( ) : void
Результат void

EnableVirtualGroups() защищенный Метод

Do the plumbing to enable groups on a virtual list
protected EnableVirtualGroups ( ) : void
Результат void

EnsureNthGroupVisible() публичный Метод

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
Результат void

FindMatchInRange() защищенный Метод

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
Результат int

GetCheckState() защищенный Метод

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
Результат CheckState?

GetDisplayOrderOfItemIndex() публичный Метод

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
Результат int

GetItemCount() публичный Метод

Return the number of items in the list
public GetItemCount ( ) : int
Результат int

GetLastItemInDisplayOrder() публичный Метод

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
Результат BrightIdeasSoftware.OLVListItem

GetModelObject() публичный Метод

Return the model object at the given index
public GetModelObject ( int index ) : object
index int Index of the model object to be returned
Результат object

GetNextItem() публичный Метод

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
Результат BrightIdeasSoftware.OLVListItem

GetNthItemInDisplayOrder() публичный Метод

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
Результат BrightIdeasSoftware.OLVListItem

GetPreviousItem() публичный Метод

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
Результат BrightIdeasSoftware.OLVListItem

HandleCacheVirtualItems() защищенный Метод

Handle the CacheVirtualItems event
protected HandleCacheVirtualItems ( object sender, System.Windows.Forms.CacheVirtualItemsEventArgs e ) : void
sender object
e System.Windows.Forms.CacheVirtualItemsEventArgs
Результат void

HandleRetrieveVirtualItem() защищенный Метод

Handle a RetrieveVirtualItem
protected HandleRetrieveVirtualItem ( object sender, System.Windows.Forms.RetrieveVirtualItemEventArgs e ) : void
sender object
e System.Windows.Forms.RetrieveVirtualItemEventArgs
Результат void

HandleSearchForVirtualItem() защищенный Метод

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
Результат void

IndexOf() публичный Метод

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
Результат int

MakeGroups() защищенный Метод

Make a list of groups that should be shown according to the given parameters
protected MakeGroups ( BrightIdeasSoftware.GroupingParameters parms ) : IList
parms BrightIdeasSoftware.GroupingParameters
Результат IList

MakeListViewItem() публичный Метод

Create a OLVListItem for given row index
public MakeListViewItem ( int itemIndex ) : BrightIdeasSoftware.OLVListItem
itemIndex int The index of the row that is needed
Результат BrightIdeasSoftware.OLVListItem

ModelToItem() публичный Метод

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
Результат BrightIdeasSoftware.OLVListItem

PostProcessRows() защищенный Метод

On virtual lists, this cannot work.
protected PostProcessRows ( ) : void
Результат void

PutCheckState() защищенный Метод

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
Результат CheckState

RefreshItem() публичный Метод

Refresh the given item in the list
public RefreshItem ( BrightIdeasSoftware.OLVListItem olvi ) : void
olvi BrightIdeasSoftware.OLVListItem The item to refresh
Результат void

RefreshObjects() публичный Метод

Update the rows that are showing the given objects
This method does not resort the items.
public RefreshObjects ( IList modelObjects ) : void
modelObjects IList
Результат void

RefreshSelectedObjects() публичный Метод

Update the rows that are selected
This method does not resort or regroup the view.
public RefreshSelectedObjects ( ) : void
Результат void

RemoveObjects() публичный Метод

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
Результат void

SelectObject() публичный Метод

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?
Результат void

SelectObjects() публичный Метод

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
Результат void

SetObjects() публичный Метод

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.
Результат void

SetVirtualListSize() защищенный Метод

Change the size of the list
protected SetVirtualListSize ( int newSize ) : void
newSize int
Результат void

TakeOwnershipOfObjects() защищенный Метод

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
Результат void

UpdateFiltering() защищенный Метод

Change the state of the control to reflect changes in filtering
protected UpdateFiltering ( ) : void
Результат void

UpdateVirtualListSize() публичный Метод

Change the size of the virtual list so that it matches its data source
public UpdateVirtualListSize ( ) : void
Результат void

VirtualObjectListView() публичный Метод

Create a VirtualObjectListView
public VirtualObjectListView ( ) : System
Результат System