Solved

Hide cols in TStringGrid

Posted on 1997-03-30
5
659 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

786 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