Recent

Author Topic: [SOLVED] TStringGrid col and column relationship  (Read 689 times)

EganSolo

  • Sr. Member
  • ****
  • Posts: 388
[SOLVED] TStringGrid col and column relationship
« on: June 10, 2025, 03:47:49 am »
What's the relationship between col and column in TStringGrid?

Say I have a grid with eight columns, some visible and some not. For instance, suppose columns 2,3 and 4 are not visible, then I'm assuming that the relationship between column and col indices is as follows:
ColumnCol
00
11
2-
3-
4-
51
62
73

For static grids, where the columns are known at design time, the mapping can be done in code, but for dynamic grids that build their columns at run-time, there's a need to figure out the mapping between columns and cols.

When handling an event such as Drawcell, the parameter is a col index. Is there a method to tell me the equivalent column index, or must I code for this?

Thanks.
 
« Last Edit: June 11, 2025, 11:50:27 pm by EganSolo »

wp

  • Hero Member
  • *****
  • Posts: 13266
Re: TStringGrid col and column relationship
« Reply #1 on: June 10, 2025, 11:07:39 am »
If you mean with "Col" the column index passed to the OnDrawCell or OnPrepareCanvas event, and with "Column" a column added to the Columns index, then I would say that it does not matter wheter a column is hidden or not. Painting iterates over all cells, if a cell is in a hidden column then the painting method just exits immediately. Therefore the relation between the ACol parameter and the Column.Index is always: ACol := Column.Index + FixedCols.

EganSolo

  • Sr. Member
  • ****
  • Posts: 388
Re: TStringGrid col and column relationship
« Reply #2 on: June 11, 2025, 11:50:12 pm »
Thanks wp! Really appreciate the answer!

 

TinyPortal © 2005-2018