BrightIdeasSoftware.ObjectListView.CalculateReasonableTileSize C# (CSharp) Method

CalculateReasonableTileSize() public method

Give the listview a reasonable size of its tiles, based on the number of lines of information that each tile is going to display.
public CalculateReasonableTileSize ( ) : void
return void
        public virtual void CalculateReasonableTileSize()
        {
            if (this.Columns.Count <= 0)
                return;

            List<OLVColumn> columns = this.AllColumns.FindAll(delegate(OLVColumn x) {
                return (x.Index == 0) || x.IsTileViewColumn;
            });

            int imageHeight = (this.LargeImageList == null ? 16 : this.LargeImageList.ImageSize.Height);
            int dataHeight = (this.Font.Height + 1) * columns.Count;
            int tileWidth = (this.TileSize.Width == 0 ? 200 : this.TileSize.Width);
            int tileHeight = Math.Max(this.TileSize.Height, Math.Max(imageHeight, dataHeight));
            this.TileSize = new Size(tileWidth, tileHeight);
        }

Usage Example

        /// <summary>
        /// The user has pressed OK. Do what's requied.
        /// </summary>
        /// <param name="olv"></param>
        /// <param name="view"></param>
        protected void Apply(ObjectListView olv, View view)
        {
            olv.Freeze();

            // Update the column definitions to reflect whether they have been hidden
            if (view == View.Details)
            {
                foreach (OLVColumn col in olv.AllColumns)
                {
                    col.IsVisible = this.MapColumnToVisible[col];
                }
            }
            else
            {
                foreach (OLVColumn col in olv.AllColumns)
                {
                    col.IsTileViewColumn = this.MapColumnToVisible[col];
                }
            }

            // Collect the columns are still visible
            List <OLVColumn> visibleColumns = this.RearrangableColumns.FindAll(
                delegate(OLVColumn x) { return(this.MapColumnToVisible[x]); });

            // Detail view and Tile view have to be handled in different ways.
            if (view == View.Details)
            {
                // Of the still visible columns, change DisplayIndex to reflect their position in the rearranged list
                olv.ChangeToFilteredColumns(view);
                foreach (OLVColumn col in visibleColumns)
                {
                    col.DisplayIndex     = visibleColumns.IndexOf((OLVColumn)col);
                    col.LastDisplayIndex = col.DisplayIndex;
                }
            }
            else
            {
                // In Tile view, DisplayOrder does nothing. So to change the display order, we have to change the
                // order of the columns in the Columns property.
                // Remember, the primary column is special and has to remain first!
                OLVColumn primaryColumn = this.AllColumns[0];
                visibleColumns.Remove(primaryColumn);

                olv.Columns.Clear();
                olv.Columns.Add(primaryColumn);
                olv.Columns.AddRange(visibleColumns.ToArray());
                olv.CalculateReasonableTileSize();
            }

            olv.Unfreeze();
        }
ObjectListView