SectionShowHide

One section of one worksheet, hidden or shown. The three pieces it needs are already classes: SectionMap says where each section starts and ends, ShowHide holds the choice for every variable, and ShowHideLayout writes the sheet. This binds the three so the section button and the section form share one body.

WHERE THE USER HAS TO STAND

A section title is written on one line of the sheet and nowhere else:

HList row 5 VList column 2

SectionBuilder writes them there and the two numbers are copied here from it. SectionAtCell answers a block only for a cell on that line, so a click made from a data row changes nothing.

WHY THE STATE IS READ AND NEVER STORED

Hiding a section stores nothing of its own. The choice lands on each variable inside it, and State reads those variables back. So a section a user collapsed through the form, through the button, or by hiding its columns one at a time all read the same, and nothing can drift out of step.

A section holding no variable the user owns answers Fixed, and CanChange is False for it. Offering an action that does nothing is worse than refusing it.

Depends on: SectionMap, ShowHide, ShowHideLayout, The line the section titles are written on. Both numbers are SectionBuilder's, (HLIST_SEC_ROW and VLIST_SEC_COL) and mean nothing without it.

Version: 1.0 (2026-08-14)

Instantiation

Create #

create

Bind a section toggle to one worksheet

Signature:

Public Function Create(ByVal secMap As SectionMap, _
                       ByVal entries As ShowHide, _
                       ByVal layout As ShowHideLayout) As SectionShowHide

The factory.

Parameters:

  • secMap: SectionMap. The sections of the sheet.
  • entries: ShowHide. The variables of the sheet and their choices.
  • layout: ShowHideLayout. The sheet the choices are written to.

Returns: SectionShowHide. The toggle, ready to read and write.

Throws:

  • ProjectError.ObjectNotInitialized When any of the three is Nothing.

Bind #

bind

Take the three pieces the toggle works with

Signature:

Public Sub Bind(ByVal secMap As SectionMap, _
                ByVal entries As ShowHide, _
                ByVal layout As ShowHideLayout)

Public because the factory calls it on a fresh instance.

Parameters:

  • secMap: SectionMap. The sections of the sheet.
  • entries: ShowHide. The variables of the sheet and their choices.
  • layout: ShowHideLayout. The sheet the choices are written to.

Accessors

Count #

count

How many sections the sheet carries

Signature:

Public Property Get Count() As Long

What the toggle is bound to.


Wksh #

wksh

The worksheet the toggle writes to

Signature:

Public Property Get Wksh() As Worksheet

SectionNameAt #

section-name-at

The title of one section

Signature:

Public Function SectionNameAt(ByVal index As Long) As String

Parameters:

  • index: Long. A one based section index.

Returns: String. The title SectionBuilder wrote.


Where the user is standing

TitleLine #

title-line

The row or column the section titles are written on

Signature:

Public Property Get TitleLine() As Long

Turning a selected cell into a section.

A row number on an HList sheet and a column number on a VList one, which is the same split ShowHideLayout makes for the hiding axis itself.

Returns: Long. The line the titles sit on.


SectionAtCell #

section-at-cell

The section one selected cell stands on

Signature:

Public Function SectionAtCell(ByVal cellRng As Range) As Long

The answer is a section only when the cell sits on the title line. A cell in a data row belongs to a section too, and reading it as one is what let a second press of the button collapse a section the user never pointed at: hiding the columns of a section moves the cursor onto the next visible column, and that column is inside the next section.

A multi-cell selection is read from its first cell.

Parameters:

  • cellRng: Range. What the user has selected.

Returns: Long. A one based section index, or 0 when the cell names no section.


TitleCell #

title-cell

The cell holding the title of one section

Signature:

Public Function TitleCell(ByVal index As Long) As Range

Where the caller puts the cursor once a section is shown again, so the next press of the button acts on the section the user is looking at.

Parameters:

  • index: Long. A one based section index.

Returns: Range. The title cell, or Nothing when the index names no section.


Reading and writing one section

State #

state

Where one section stands

Signature:

Public Function State(ByVal index As Long) As Byte

The state of a section, and changing it.

Parameters:

  • index: Long. A one based section index.

Returns: Byte. A ShowHideRangeState value.


IsHidden #

is-hidden

Whether one section is hidden right now

Signature:

Public Function IsHidden(ByVal index As Long) As Boolean

A section is hidden when every variable the user owns inside it is hidden. A section showing some of its variables answers False, so the next action offered for it is to hide the rest.

Parameters:

  • index: Long. A one based section index.

Returns: Boolean. True when the section is collapsed.


CanChange #

can-change

Whether the user may hide or show one section

Signature:

Public Function CanChange(ByVal index As Long) As Boolean

False for a section holding no variable the user owns, and for an index outside the map. Both are sections the toggle would leave exactly as it found them.

Parameters:

  • index: Long. A one based section index.

Returns: Boolean. True when the section follows the user.


SetHidden #

set-hidden

Hide or show one whole section

Signature:

Public Function SetHidden(ByVal index As Long, ByVal hidden As Boolean) As Long

The choice lands on every variable of the section the user owns, and the sheet is then put in step through the layout. A mandatory or a locked variable keeps its state, so a section holding one never disappears whole.

Parameters:

  • index: Long. A one based section index.
  • hidden: Boolean. True to collapse the section.

Returns: Long. How many variables the call changed.


SetAllHidden #

set-all-hidden

Hide or show every section of the sheet

Signature:

Public Function SetAllHidden(ByVal hidden As Boolean) As Long

One pass over the map and one pass over the sheet. The section form's two option buttons reach it when no single section is picked.

Parameters:

  • hidden: Boolean. True to collapse them all.

Returns: Long. How many variables the call changed.


Internal members (not exported)

Helpers

ThrowError #

throw-error

Raise a project error naming this class

Signature:

Private Sub ThrowError(ByVal errNumber As ProjectError, ByVal message As String)

Private workers.

Parameters:


Used in (3 file(s))