Solved

Hide cols in TStringGrid

Posted on 1997-03-30
5
654 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:ChrisGin
  • 2
  • 2
5 Comments
 

Accepted Solution

by:
boabyte earned 25 total points
ID: 1335074
There are two possible solutions, depending upon your need to
access the data.

1. If there is no need to cross-reference data, just update
   the string grid with the fields you want shown.

2. If you do need to cross-reference data: Create a dynamic
   mutlidimensional array. (this is if all fields can be
   converted to string types.) Then read info from binary file
   into array. This allows you to show only certain fields, but
   still allows cross-reference of fields.
0
 

Author Comment

by:ChrisGin
ID: 1335075
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.....
0
 

Expert Comment

by:boabyte
ID: 1335076
Could you use the StringGrid.Cells(Col,Row) or StringGrid.Row
property to use as the StringGrid index?
0
 

Author Comment

by:ChrisGin
ID: 1335077
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?
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335078
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.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now