System.Windows.Forms.ListView.CalculateRowsAndCols C# (CSharp) Method

CalculateRowsAndCols() public method

public CalculateRowsAndCols ( Size item_size, bool left_aligned, int x_spacing, int y_spacing ) : void
item_size System.Drawing.Size
left_aligned bool
x_spacing int
y_spacing int
return void
		void CalculateRowsAndCols (Size item_size, bool left_aligned, int x_spacing, int y_spacing)
		{
			Rectangle area = ClientRectangle;

			if (UseCustomColumnWidth)
				CalculateCustomColumnWidth ();
			if (UsingGroups) {
				// When groups are used the alignment is always top-aligned
				rows = 0;
				cols = 0;
				int items = 0;

				groups.DefaultGroup.ItemCount = GetDefaultGroupItems ();
				for (int i = 0; i < groups.InternalCount; i++) {
					ListViewGroup group = groups.GetInternalGroup (i);
					int items_in_group = group.GetActualItemCount ();

					if (items_in_group == 0)
						continue;

					int group_cols = (int) Math.Floor ((double)(area.Width - v_scroll.Width + x_spacing) / (double)(item_size.Width + x_spacing));
					if (group_cols <= 0)
						group_cols = 1;
					int group_rows = (int) Math.Ceiling ((double)items_in_group / (double)group_cols);

					group.starting_row = rows;
					group.rows = group_rows;
					group.starting_item = items;
					group.current_item = 0; // Reset layout

					cols = Math.Max (group_cols, cols);
					rows += group_rows;
					items += items_in_group;
				}
			} else
			{
				// Simple matrix if no groups are used
				if (left_aligned) {
					rows = (int) Math.Floor ((double)(area.Height - h_scroll.Height + y_spacing) / (double)(item_size.Height + y_spacing));
					if (rows <= 0)
						rows = 1;
					cols = (int) Math.Ceiling ((double)items.Count / (double)rows);
				} else {
					if (UseCustomColumnWidth)
						cols = (int) Math.Floor ((double)(area.Width - v_scroll.Width) / (double)(custom_column_width));
					else
						cols = (int) Math.Floor ((double)(area.Width - v_scroll.Width + x_spacing) / (double)(item_size.Width + x_spacing));

					if (cols < 1)
						cols = 1;

					rows = (int) Math.Ceiling ((double)items.Count / (double)cols);
				}
			}

			item_index_matrix = new int [rows, cols];
		}
ListView