Solved

Hide cols in TStringGrid

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

765 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