public void SelectAll() { List<RowIdentifier> allItems = new List<RowIdentifier>( ItemList.Count ); for( int i = 0; i < ItemList.Count; i++ ) { RowIdentifier rowIdentifier = new NonGroupRow( ItemList[i] ); allItems.Add( rowIdentifier ); } SelectedItems.ClearAndAdd( allItems.ToArray() ); Invalidate(); }
/// <summary> /// Returns the number of items in the list adjusted for the group items. /// This method will also create a bit array of types <seealso cref="_positionTypes"/> /// </summary> /// <returns></returns> private int CalculateListItems() { using( new EnforceLazyLayout( this ) ) { if( _rowInformation == null ) { PositionedRowIdentifier[] trackableItems = new PositionedRowIdentifier[3]; trackableItems[0] = _focusedItem; if( _lastCalculatedRowInformation != null ) { if( FocusedItem != null ) { if( LineStart < _lastCalculatedRowInformation.Count ) { trackableItems[1] = new PositionedRowIdentifier( _lastCalculatedRowInformation[LineStart], LineStart ); } RowIdentifier nextValidRow = locateNearestRowThatsStillValid( FocusedItem, ItemList, _lastCalculatedRowInformation ); if( nextValidRow != null ) { trackableItems[2] = new PositionedRowIdentifier( nextValidRow, 0 ); } } } Column[] groupColumns = ListControl.Columns.GroupedItems.ToArray(); object lastItem = null; _lastCalculatedRowInformation = _rowInformation = new List<RowIdentifier>( ItemList.Count ); int hideRowGroupIndex = -1; List<PositionedRowIdentifier> newSelection = new List<PositionedRowIdentifier>(); GroupIdentifier[] activeGroups = new GroupIdentifier[groupColumns.Length]; object[] listItems = ItemList.ToArray(); for( int i = 0; i < ItemList.Count; i++ ) { object item = ItemList[i]; int groupIndex = ItemInNewGroup( groupColumns, item, lastItem ); if( groupIndex != -1 ) { for( int iGroup = groupIndex; iGroup < groupColumns.Length; iGroup++ ) { GroupIdentifier gi = new GroupIdentifier( i, listItems, Columns, iGroup, item ); int hideGroupIndex = hideRowGroupIndex; if( hideRowGroupIndex == -1 || iGroup <= hideRowGroupIndex ) { if( GetGroupState( gi ) == GroupState.Collapsed ) { hideGroupIndex = iGroup; if( groupIndex <= hideRowGroupIndex ) { hideRowGroupIndex = -1; } } else { hideRowGroupIndex = hideGroupIndex = -1; } } if( hideRowGroupIndex == -1 ) { HandleSyncing( gi, _rowInformation.Count, trackableItems, newSelection ); _rowInformation.Add( gi ); } if( activeGroups[iGroup] != null ) { activeGroups[iGroup].End = i; } activeGroups[iGroup] = gi; hideRowGroupIndex = hideGroupIndex; } } if( hideRowGroupIndex == -1 ) { RowIdentifier ri = new NonGroupRow( item ); HandleSyncing( ri, _rowInformation.Count, trackableItems, newSelection ); _rowInformation.Add( ri ); } lastItem = item; } foreach( GroupIdentifier gi in activeGroups ) { if( gi != null ) { gi.End = ItemList.Count; } } if( VerticalScrollbarVisible ) { int newMax = _rowInformation.Count == 0 ? 0 : _rowInformation.Count - 1; if( VScrollbar.Value >= newMax ) { VScrollbar.Value = newMax; } VScrollbar.Maximum = newMax; } if( trackableItems[1] != null ) { LineStart = trackableItems[1].Position; } if( _focusedItem != null && !IsSelectedItemValid( _focusedItem ) ) { if( trackableItems[2] != null && IsSelectedItemValid( trackableItems[2] ) ) { PositionedRowIdentifier oldFocusedItem = _focusedItem; if( _focusedItem != trackableItems[2] ) { _focusedItem = trackableItems[2]; ListControl.FireFocusChanged( oldFocusedItem == null ? null : oldFocusedItem.RowIdentifier, _focusedItem == null ? null : _focusedItem.RowIdentifier ); } newSelection.Add( _focusedItem ); } else { int newPosition; if( _focusedItem.Position >= _rowInformation.Count ) { newPosition = _rowInformation.Count - 1; } else { newPosition = _focusedItem.Position; } if( newPosition >= 0 ) { PositionedRowIdentifier si = new PositionedRowIdentifier( _rowInformation[newPosition], newPosition ); FocusedItem = si; newSelection.Add( _focusedItem ); } else { FocusedItem = null; } } } RowIdentifier[] rowItemsToSelect = new RowIdentifier[newSelection.Count]; int j = 0; foreach( PositionedRowIdentifier pri in newSelection ) { rowItemsToSelect[j++] = pri.RowIdentifier; } SelectedItems.ClearAndAdd( rowItemsToSelect ); if( SelectedItems.Count == 0 && FocusedItem == null && VScrollbar != null && VScrollbar.Visible ) { VScrollbar.Value = 0; } } _mapOfPositions = null; } ListControl.OnCalculatedGroupRows( EventArgs.Empty ); return _rowInformation.Count; }