ColPositionproperty
Sets the position of an MSHFlexGrid column, allowing you to move columns to specific positions.
Syntax
PROPERTY ColPosition (BYVAL Index AS LONG, BYVAL newPos AS LONG)
Parameters
| Name | Description | |
|---|---|---|
Index | The current zero-based index of the column you want to move. | |
newPos | The target zero-based index where the column should be placed. | |
BandNumber | Optional. A Long value that specifies the band that contains the column. |
Description
Sets the position of an MSHFlexGrid column, allowing you to move columns to specific positions.
Remarks
Unlike ColPos (which returns a pixel/twip coordinate), ColPosition is used to move a column from its current index to a new index location.
When a column is moved, all other columns between the old and new positions automatically shift to fill the gap.
This property moves the entire column including its data, ColWidth, and individual cell formatting.
This property is primarily intended for grids in unbound mode. If the grid is bound to a data source, the order is typically governed by the fields in the underlying recordset; manually moving columns may be overwritten upon a data refresh.
Examples
' Moves column 2 to the far left grid.ColPosition(2) = 0
' Moving column 0 to position 1 effectively swaps the two grid.ColPosition(0) = 1
Reference
- Documented in Windows/Windows GUI/MSHFlexGrid Class.md
- Topic: Microsoft Hierarchical Grid