Exemplo n.º 1
0
        /// <summary>
        /// Automatically resizes the last column to take up all available free space.
        /// </summary>
        /// <param name="listView"></param>
        public static void AutoSizeLastColumn(this ListView listView)
        {
#if !__MonoCS__
            if (listView.AnyParent(parent => parent.Disposing || parent.IsDisposed))
            {
                return;
            }

            var columnHeaders = listView.Columns.OfType <ColumnHeader>().ToArray();
            if (!columnHeaders.Any())
            {
                return;
            }

            var maxDisplayIndex = columnHeaders.Max(header => header.DisplayIndex);
            var lastColumn      = columnHeaders.LastOrDefault(header => header.DisplayIndex == maxDisplayIndex);
            if (lastColumn != null)
            {
                listView.SuspendDrawing();
                lastColumn.AutoResize();
                lastColumn.Width -= 2; // TODO: Figure out why this is necessary on some ListViews (e.g., FormFileNamerPreferences)
                listView.ResumeDrawing();
            }
#endif
        }