Exemple #1
0
		/// <summary>
		/// Resizes the columns of a given list view according to the passed
		/// column widths.
		/// </summary>
		/// <param name="listView">The list view.</param>
		/// <param name="columnToStretch">The column to stretch.</param>
		/// <param name="options">The options.</param>
		public static void ResizeListViewColumns(
			ListView listView,
			int columnToStretch,
			ListViewSizeOptions options )
		{
			int width = listView.ClientRectangle.Width;

			if ( options.SubtractVerticalScrollBarWidth )
			{
				width -= VerticalScrollBarWidth;
			}

			width -= DefaultSubtractWidth;

			// The widths of all but the column to stretch.
			for ( int i = 0; i < listView.Columns.Count; ++i )
			{
				if ( i != columnToStretch )
				{
					width -= listView.Columns[i].Width;
				}
			}

			listView.Columns[columnToStretch].Width = width;
		}
Exemple #2
0
		/// <summary>
		/// Resizes the columns of a given list view according to the passed
		/// column widths.
		/// </summary>
		/// <param name="listView">The list view.</param>
		/// <param name="options">The options.</param>
		/// <param name="sizes">Pass a value smaller than 1.0 to specify
		/// the value in percent (0.30 e.g. means 30%), pass a value
		/// of 0.0 to not size the column.</param>
		public static void ResizeListViewColumns(
			ListView listView,
			ListViewSizeOptions options,
			params double[] sizes )
		{
			if ( sizes.Length != listView.Columns.Count )
			{
				throw new ArgumentException(
					LocalizationHelper.Format(
					Resources.Str_ZetaLib_Windows_Common_FormHelper_01,
					LocalizationHelper.CreatePair( @"ColumnCount", listView.Columns.Count ),
					LocalizationHelper.CreatePair( @"SizedCount", sizes.Length ) ),
					@"sizes" );
			}
			else
			{
				// Avoid endless calls.
				if ( !insideSizes.Contains( listView ) )
				{
					insideSizes.Add( listView );

					try
					{
						int width = listView.ClientRectangle.Width;
						if ( options.SubtractVerticalScrollBarWidth )
						{
							width -= VerticalScrollBarWidth;
						}

						width -= DefaultSubtractWidth;

						// First pass - subtract all absolute sizes.
						for ( int i = 0; i < listView.Columns.Count; ++i )
						{
							double size = sizes[i];

							if ( size == 0.0 )
							{
								width -= listView.Columns[i].Width;
							}
							else if ( size <= 1.0 )
							{
								// Do nothing.
							}
							else
							{
								width -= Convert.ToInt32( size );
							}
						}

						// Second pass - actually resize.
						for ( int i = 0; i < listView.Columns.Count; ++i )
						{
							double size = sizes[i];

							if ( size <= 0.0001 )
							{
								// Do nothing.
							}
							else if ( size <= 1.0 )
							{
								// Size percentual.
								int theWidth =
									Convert.ToInt32( (((double)width) * size) );
								ColumnHeader col = listView.Columns[i];
								col.Width = theWidth;
							}
							else
							{
								// Size absolute.
								listView.Columns[i].Width =
									Convert.ToInt32( size );
							}
						}
					}
					finally
					{
						insideSizes.Remove( listView );
					}
				}
			}
		}
Exemple #3
0
		/// <summary>
		/// Resizes the columns of a given list view according to the passed
		/// column widths.
		/// </summary>
		/// <param name="listView">The list view.</param>
		/// <param name="options">The options.</param>
		public static void ResizeListViewColumns(
			ListView listView,
			ListViewSizeOptions options )
		{
			ResizeListViewColumns( listView, listView.Columns.Count - 1, options );
		}