?? objectlistview.cs
字號:
/*
* ObjectListView - A listview to show various aspects of a collection of objects
*
* Author: Phillip Piper
* Date: 9/10/2006 11:15 AM
*
* Change log:
* 2009-02-24 JPP - Fix bug where double-clicking VERY quickly on two different cells
* could give two editors
* - Maintain focused item when rebuilding list (SF #2547060)
* 2009-02-22 JPP - Reworked checkboxes so that events are triggered for virtual lists
* 2009-02-15 JPP - Added ObjectListView.ConfigureAutoComplete utility method
* 2009-02-02 JPP - Fixed bug with AlwaysGroupByColumn where column header clicks would not resort groups.
* 2009-02-01 JPP - OLVColumn.CheckBoxes and TriStateCheckBoxes now work.
* 2009-01-28 JPP - Complete overhaul of renderers!
* - Use IRenderer
* - Added ObjectListView.ItemRenderer to draw whole items
* 2009-01-23 JPP - Simple Checkboxes now work properly
* - Added TriStateCheckBoxes property to control whether the user can
* set the row checkbox to have the Indeterminate value
* - CheckState property is now just a wrapper around the StateImageIndex property
* 2009-01-20 JPP - Changed to always draw columns when owner drawn, rather than falling back on DrawDefault.
* This simplified several owner drawn problems
* - Added DefaultRenderer property to help with the above
* - HotItem background color is applied to all cells even when FullRowSelect is false
* - Allow grouping by CheckedAspectName columns
* - Commented out experimental animations. Still needs work.
* 2009-01-17 JPP - Added HotItemStyle and UseHotItem to highlight the row under the cursor
* - Added UseCustomSelectionColors property
* - Owner draw mode now honors ForeColor and BackColor settings on the list
* 2009-01-16 JPP - Changed to use EditorRegistry rather than hard coding cell editors
* 2009-01-10 JPP - Changed to use Equals() method rather than == to compare model objects.
* v2.0.1
* 2009-01-08 JPP - Fixed long-standing "multiple columns generated" problem.
* Thanks to pinkjones for his help with solving this one!
* - Added EnsureGroupVisible()
* 2009-01-07 JPP - Made all public and protected methods virtual
* - FinishCellEditing, PossibleFinishCellEditing and CancelCellEditing are now public
* 2008-12-20 JPP - Fixed bug with group comparisons when a group key was null (SF#2445761)
* 2008-12-19 JPP - Fixed bug with space filling columns and layout events
* - Fixed RowHeight so that it only changes the row height, not the width of the images.
* v2.0
* 2008-12-10 JPP - Handle Backspace key. Resets the seach-by-typing state without delay
* - Made some changes to the column collection editor to try and avoid
* the multiple column generation problem.
* - Updated some documentation
* 2008-12-07 JPP - Search-by-typing now works when showing groups
* - Added BeforeSearching and AfterSearching events which are triggered when the user types
* into the list.
* - Added secondary sort information to Before/AfterSorting events
* - Reorganized group sorting code. Now triggers Sorting events.
* - Added GetItemIndexInDisplayOrder()
* - Tweaked in the interaction of the column editor with the IDE so that we (normally)
* don't rely on a hack to find the owning ObjectListView
* - Changed all 'DefaultValue(typeof(Color), "Empty")' to 'DefaultValue(typeof(Color), "")'
* since the first does not given Color.Empty as I thought, but the second does.
* 2008-11-28 JPP - Fixed long standing bug with horizontal scrollbar when shrinking the window.
* (thanks to Bartosz Borowik)
* 2008-11-25 JPP - Added support for dynamic tooltips
* - Split out comparers and header controls stuff into their own files
* 2008-11-21 JPP - Fixed bug where enabling grouping when there was not a sort column would not
* produce a grouped list. Grouping column now defaults to column 0.
* - Preserve selection on virtual lists when sorting
* 2008-11-20 JPP - Added ability to search by sort column to ObjectListView. Unified this with
* ability that was already in VirtualObjectListView
* 2008-11-19 JPP - Fixed bug in ChangeToFilteredColumns() where DisplayOrder was not always restored correctly.
* 2008-10-29 JPP - Event argument blocks moved to directly within the namespace, rather than being
* nested inside ObjectListView class.
* - Removed OLVColumn.CellEditor since it was never used.
* - Marked OLVColumn.AspectGetterAutoGenerated as obsolete (it has not been used for
* several versions now).
* 2008-10-28 JPP - SelectedObjects is now an IList, rather than an ArrayList. This allows
* it to accept generic list (eg List<File>).
* 2008-10-09 JPP - Support indeterminate checkbox values.
* [BREAKING CHANGE] CheckStateGetter/CheckStatePutter now use CheckState types only.
* BooleanCheckStateGetter and BooleanCheckStatePutter added to ease transition.
* 2008-10-08 JPP - Added setFocus parameter to SelectObject(), which allows focus to be set
* at the same time as selecting.
* 2008-09-27 JPP - BIG CHANGE: Fissioned this file into separate files for each component
* 2008-09-24 JPP - Corrected bug with owner drawn lists where a column 0 with a renderer
* would draw at column 0 even if column 0 was dragged to another position.
* - Correctly handle space filling columns when columns are added/removed
* 2008-09-16 JPP - Consistently use try..finally for BeginUpdate()/EndUpdate() pairs
* 2008-08-24 JPP - If LastSortOrder is None when adding objects, don't force a resort.
* 2008-08-22 JPP - Catch and ignore some problems with setting TopIndex on FastObjectListViews.
* 2008-08-05 JPP - In the right-click column select menu, columns are now sorted by display order, rather than alphabetically
* v1.13
* 2008-07-23 JPP - Consistently use copy-on-write semantics with Add/RemoveObject methods
* 2008-07-10 JPP - Enable validation on cell editors through a CellEditValidating event.
* (thanks to Artiom Chilaru for the initial suggestion and implementation).
* 2008-07-09 JPP - Added HeaderControl.Handle to allow OLV to be used within UserControls.
* (thanks to Michael Coffey for tracking this down).
* 2008-06-23 JPP - Split the more generally useful CopyObjectsToClipboard() method
* out of CopySelectionToClipboard()
* 2008-06-22 JPP - Added AlwaysGroupByColumn and AlwaysGroupBySortOrder, which
* force the list view to always be grouped by a particular column.
* 2008-05-31 JPP - Allow check boxes on FastObjectListViews
* - Added CheckedObject and CheckedObjects properties
* 2008-05-11 JPP - Allow selection foreground and background colors to be changed.
* Windows doesn't allow this, so we can only make it happen when owner
* drawing. Set the HighlightForegroundColor and HighlightBackgroundColor
* properties and then call EnableCustomSelectionColors().
* v1.12
* 2008-05-08 JPP - Fixed bug where the column select menu would not appear if the
* ObjectListView has a context menu installed.
* 2008-05-05 JPP - Non detail views can now be owner drawn. The renderer installed for
* primary column is given the chance to render the whole item.
* See BusinessCardRenderer in the demo for an example.
* - BREAKING CHANGE: RenderDelegate now returns a bool to indicate if default
* rendering should be done. Previously returned void. Only important if your
* code used RendererDelegate directly. Renderers derived from BaseRenderer
* are unchanged.
* 2008-05-03 JPP - Changed cell editing to use values directly when the values are Strings.
* Previously, values were always handed to the AspectToStringConverter.
* - When editing a cell, tabbing no longer tries to edit the next subitem
* when not in details view!
* 2008-05-02 JPP - MappedImageRenderer can now handle a Aspects that return a collection
* of values. Each value will be drawn as its own image.
* - Made AddObjects() and RemoveObjects() work for all flavours (or at least not crash)
* - Fixed bug with clearing virtual lists that has been scrolled vertically
* - Made TopItemIndex work with virtual lists.
* 2008-05-01 JPP - Added AddObjects() and RemoveObjects() to allow faster mods to the list
* - Reorganised public properties. Now alphabetical.
* - Made the class ObjectListViewState internal, as it always should have been.
* v1.11
* 2008-04-29 JPP - Preserve scroll position when building the list or changing columns.
* - Added TopItemIndex property. Due to problems with the underlying control, this
* property is not always reliable. See property docs for info.
* 2008-04-27 JPP - Added SelectedIndex property.
* - Use a different, more general strategy to handle Invoke(). Removed all delegates
* that were only declared to support Invoke().
* - Check all native structures for 64-bit correctness.
* 2008-04-25 JPP - Released on SourceForge.
* 2008-04-13 JPP - Added ColumnRightClick event.
* - Made the assembly CLS-compliant. To do this, our cell editors were made internal, and
* the constraint on FlagRenderer template parameter was removed (the type must still
* be an IConvertible, but if it isn't, the error will be caught at runtime, not compile time).
* 2008-04-12 JPP - Changed HandleHeaderRightClick() to have a columnIndex parameter, which tells
* exactly which column was right-clicked.
* 2008-03-31 JPP - Added SaveState() and RestoreState()
* - When cell editing, scrolling with a mouse wheel now ends the edit operation.
* v1.10
* 2008-03-25 JPP - Added space filling columns. See OLVColumn.FreeSpaceProportion property for details.
* A space filling columns fills all (or a portion) of the width unoccupied by other columns.
* 2008-03-23 JPP - Finished tinkering with support for Mono. Compile with conditional compilation symbol 'MONO'
* to enable. On Windows, current problems with Mono:
* - grid lines on virtual lists crashes
* - when grouped, items sometimes are not drawn when any item is scrolled out of view
* - i can't seem to get owner drawing to work
* - when editing cell values, the editing controls always appear behind the listview,
* where they function fine -- the user just can't see them :-)
* 2008-03-16 JPP - Added some methods suggested by Chris Marlowe (thanks for the suggestions Chris)
* - ClearObjects()
* - GetCheckedObject(), GetCheckedObjects()
* - GetItemAt() variation that gets both the item and the column under a point
* 2008-02-28 JPP - Fixed bug with subitem colors when using OwnerDrawn lists and a RowFormatter.
* v1.9.1
* 2008-01-29 JPP - Fixed bug that caused owner-drawn virtual lists to use 100% CPU
* - Added FlagRenderer to help draw bitwise-OR'ed flag values
* 2008-01-23 JPP - Fixed bug (introduced in v1.9) that made alternate row colour with groups not quite right
* - Ensure that DesignerSerializationVisibility.Hidden is set on all non-browsable properties
* - Make sure that sort indicators are shown after changing which columns are visible
* 2008-01-21 JPP - Added FastObjectListView
* v1.9
* 2008-01-18 JPP - Added IncrementalUpdate()
* 2008-01-16 JPP - Right clicking on column header will allow the user to choose which columns are visible.
* Set SelectColumnsOnRightClick to false to prevent this behaviour.
* - Added ImagesRenderer to draw more than one images in a column
* - Changed the positioning of the empty list m to use all the client area. Thanks to Matze.
* 2007-12-13 JPP - Added CopySelectionToClipboard(). Ctrl-C invokes this method. Supports text
* and HTML formats.
* 2007-12-12 JPP - Added support for checkboxes via CheckStateGetter and CheckStatePutter properties.
* - Made ObjectListView and OLVColumn into partial classes so that others can extend them.
* 2007-12-09 JPP - Added ability to have hidden columns, i.e. columns that the ObjectListView knows
* about but that are not visible to the user. Controlled by OLVColumn.IsVisible.
* Added ColumnSelectionForm to the project to show how it could be used in an application.
*
* v1.8
* 2007-11-26 JPP - Cell editing fully functional
* 2007-11-21 JPP - Added SelectionChanged event. This event is triggered once when the
* selection changes, no matter how many items are selected or deselected (in
* contrast to SelectedIndexChanged which is called once for every row that
* is selected or deselected). Thanks to lupokehl42 (Daniel) for his suggestions and
* improvements on this idea.
* 2007-11-19 JPP - First take at cell editing
* 2007-11-17 JPP - Changed so that items within a group are not sorted if lastSortOrder == None
* - Only call MakeSortIndicatorImages() if we haven't already made the sort indicators
* (Corrected misspelling in the name of the method too)
* 2007-11-06 JPP - Added ability to have secondary sort criteria when sorting
* (SecondarySortColumn and SecondarySortOrder properties)
* - Added SortGroupItemsByPrimaryColumn to allow group items to be sorted by the
* primary column. Previous default was to sort by the grouping column.
* v1.7
* No big changes to this version but made to work with ListViewPrinter and released with it.
*
* 2007-11-05 JPP - Changed BaseRenderer to use DrawString() rather than TextRenderer, since TextRenderer
* does not work when printing.
* v1.6
* 2007-11-03 JPP - Fixed some bugs in the rebuilding of DataListView.
* 2007-10-31 JPP - Changed to use builtin sort indicators on XP and later. This also avoids alignment
* problems on Vista. (thanks to gravybod for the suggestion and example implementation)
* 2007-10-21 JPP - Added MinimumWidth and MaximumWidth properties to OLVColumn.
* - Added ability for BuildList() to preserve selection. Calling BuildList() directly
* tries to preserve selection; calling SetObjects() does not.
* - Added SelectAll() and DeselectAll() methods. Useful for working with large lists.
* 2007-10-08 JPP - Added GetNextItem() and GetPreviousItem(), which walk sequentially through the
* listview items, even when the view is grouped.
* - Added SelectedItem property
* 2007-09-28 JPP - Optimized aspect-to-string conversion. BuildList() 15% faster.
* - Added empty implementation of RefreshObjects() to VirtualObjectListView since
* RefreshObjects() cannot work on virtual lists.
* 2007-09-13 JPP - Corrected bug with custom sorter in VirtualObjectListView (thanks for mpgjunky)
* 2007-09-07 JPP - Corrected image scaling bug in DrawAlignedImage() (thanks to krita970)
* 2007-08-29 JPP - Allow item count labels on groups to be set per column (thanks to cmarlow for idea)
* 2007-08-14 JPP - Major rework of DataListView based on Ian Griffiths's great work
* 2007-08-11 JPP - When empty, the control can now draw a "List Empty" m
* - Added GetColumn() and GetItem() methods
* v1.5
* 2007-08-03 JPP - Support animated GIFs in ImageRenderer
* - Allow height of rows to be specified - EXPERIMENTAL!
* 2007-07-26 JPP - Optimised redrawing of owner-drawn lists by remembering the update rect
* - Allow sort indicators to be turned off
* 2007-06-30 JPP - Added RowFormatter delegate
* - Allow a different label when there is only one item in a group (thanks to cmarlow)
* v1.4
* 2007-04-12 JPP - Allow owner drawn on steriods!
* - Column headers now display sort indicators
* - ImageGetter delegates can now return ints, strings or Images
* (Images are only visible if the list is owner drawn)
* - Added OLVColumn.MakeGroupies to help with group partitioning
* - All normal listview views are now supported
* - Allow dotted aspect names, e.g. Owner.Workgroup.Name (thanks to OlafD)
* - Added SelectedObject and SelectedObjects properties
* v1.3
* 2007-03-01 JPP - Added DataListView
* - Added VirtualObjectListView
* - Added Freeze/Unfreeze capabilities
* - Allowed sort handler to be installed
* - Simplified sort comparisons: handles 95% of cases with only 6 lines of code!
* - Fixed bug with alternative line colors on unsorted lists (thanks to cmarlow)
* 2007-01-13 JPP - Fixed bug with lastSortOrder (thanks to Kwan Fu Sit)
* - Non-OLVColumns are no longer allowed
* 2007-01-04 JPP - Clear sorter before rebuilding list. 10x faster! (thanks to aaberg)
* - Include GetField in GetAspectByName() so field values can be Invoked too.
* - Fixed subtle bug in RefreshItem() that erased background colors.
* 2006-11-01 JPP - Added alternate line colouring
* 2006-10-20 JPP - Refactored all sorting comparisons and made it extendable. See ComparerManager.
* - Improved IDE integration
* - Made control DoubleBuffered
* - Added object selection methods
* 2006-10-13 JPP Implemented grouping and column sorting
* 2006-10-09 JPP Initial version
*
* TO DO:
* - Nothing?
*
* Copyright (C) 2006-2008 Phillip Piper
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* If you wish to use this code in a closed source application, please contact phillip_piper@bigfoot.com.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -