Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grid Column Headings? 1

Status
Not open for further replies.

wjs2

Programmer
Jan 3, 2001
102
US
Here is my code such that a grid is not hardwired to a particular table.


ThisForm.grdReview.recordsource = ''
Use (lcNewFile) in 0 alias NewData again exclusive
Select NewData
Dimension tblArray(1,1)
Select NewData
FieldCount = AFields(tblArray)
ThisForm.grdReview.columncount = Fieldcount
ThisForm.grdReview.recordsourcetype = 1
ThisForm.grdReview.recordsource = 'NewData'

Question: What do I have to do to get the field names in the column headings?

It has to be something like:
for columncount = 1 to FieldCount step 1
ThisForm.grdReview.Column.Header.Caption(columncount)
= trim(tblArray(columncount,1))
endfor

or something similar but I don't know what.

Thanks
Bill
 
Uuuhhh, I must be missing something. They are by default.
Dave S.
 
All the column headings just say 'Header1'

wjs
 
wjs2,

i dunno if i understood it right so correct me if am wrong. in the load property of the form, you could copy first the structure of that table to a temporary location, say "c:\windows\temp", and use the copy as the recordsource of the grid. just an idea...

torturedmind [trooper]
 
Mybe I need a give a little more detail to get to this. I have a series of forms for defining a table and importing a text file into the newly created table. By the time I get to the form that is giving me the trouble (the form where the data is actually imported), the table has been created and is empty. The table was created on a previous form and the table name and location is passed to the This form as a parm. This form is to take the text file (name and location passed in a parm) and import the first 10 records for review. Since the table name is coming in a parm also, the logical(??) place to put this code was in the Init code. Possibly I am not getting the sequence right. The data is loaded correctly into the grid but headings for the columns all say 'HEADER1'. I just thought, 'Well, your will have to load the column headings manually in this circustance.' I've never had to do it this way but then I haven't done everything there is to do in Fox Pro yet. I'm working on it.

wjs
 
wjs

the headings are like that bcoz the grid was created without any underlying data to use. you could do this instead and hope this can help:

<this is in the INIT property>
parameters oTblLoc, oTblAlias

thisform.grdReview.recordsourcetype = 1
thisform.grdReview.recordsource = oTblAlias


when the form activates (or show itself on screen), ithe grid will use whatever alias the form receives.

tell me if this helped.

torturedmind [trooper]
 
wjs2,

With Thisform.mygrid
For i =1 To .ColumnCount
With .Columns(i)
.Header1.Caption = UPPER(JUSTEXT(.ControlSource))
Endwith
Endfor
Endwith


...just a crude little example for looping through the headers and do something like you were talking about Slighthaze = NULL
 
Hi wjs2

1. If the alias is avaialbale when the grid is instantiated, you dont have to do anything. I have many search grids with common methods and events with no mention of any of the tables, and when the default alias is passed on, they all inherit the column headers from the DBC.

2. The Grid reconstruction when a cursor is recreated can create problems.. Known issue. :) To go round this issue..
ThisForm.myGrid1.RecordSource = ''
*** reconstruct the record source
ThisForm.myGrid1.RecordSource = 'myALias'
These codes takes care of that.

3. If you keep the columnCount (not keeping the default value of -1) of a grid when it is instatiated and alias specified, you could get into problem of controlling the columns.
So the way to do is..
ThisForm.myGrid1.RecordSource=&quot;&quot;
ThisForm.myGrid1.ColumnCount=-1
ThisForm.myGrid1.RecordSource=&quot;myAlias&quot;
Bingo.. all your headers will have the DBC names associated with alias fields OR it will have the field names as the headers.

4. If you have selected fields from a DBC table by SQL select, thes cursors will not have the table field names associted.. but instead will end up having the raw field names. If you use VIEWS with their captions properly set, you can use the views and avoid this problem.

5. If you still want to load the field names into an array.. use AFIELDS(aFarray,cALias)
aFarray(1,1) will give the 1st field name etc etc...

I think, point 3 is your direct answer and have a test work on this.
ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
Hi ramani,

Well I'll just kiss your ----! It was the -1 on the ColumnCount. I didn't know you could get too thourogh in programming but think that is what happened in this case. Sometimes doing nothing is the best solution.

Thanks to everyone posting responses. Even if I don't use a given soultion this time I always learn new things in here.

Bill Stratton
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top