Link to home
Start Free TrialLog in
Avatar of ChrisGin
ChrisGin

asked on

Hide cols in TStringGrid

Is it possible to have hidden columns in a TStringGrid? If not, what is the best way to store a list of records when you only want to show some fields of the records to the user? (BTW these 'records' are not database records - they are being read from a binary file.) This list will be read-only so there is no requirement for the user to be able to edit the records.
ASKER CERTIFIED SOLUTION
Avatar of boabyte
boabyte

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ChrisGin
ChrisGin

ASKER

I do have the complete set of data in an array, and I want my TStringGrid to only show one or two fields. That's fine, however to link the items in the grid with the items in the array, I need to store another field (the array index) in the grid, but I don't want the user to see it.

At the moment it's not a problem because the grid is never sorted (and therefore the index in the grid is the same as the index in the array) but that may change.....
Could you use the StringGrid.Cells(Col,Row) or StringGrid.Row
property to use as the StringGrid index?
Yes that works as long as I never sort the grid. But let's say the grid is in random order and there is no way to link the grid items back to the array without storing the array index in the grid. Can I perhaps add the extra field to the grid and set its column width to 0? Is there another 'list' control which would be better suited to what I'm trying to do?
I think BoaBytes answer is just fine.  What if you COULD store your data in a few 'invisible' columns and you then performed a sort...wouldn't you still have a need to store the references to the invisible data, since a sort would change their column location?

You mentioned setting column width to 0, like you had yet to try that.  Try it.

Why don't you simply update the references to the columns during the sort?  I've done something similar and it is not too tough.

Another option is to use OLE and link in an Excel table...with that you'll get all the functionality of Excel.  StringGrid is ot Excel, it will not come with all the functionality you desire.  Either develop workarounds, as BoaByte has suggested, or go to the Delphi Super Page and find one of the many grid components that will do exactly what you wish.