Link to home
Start Free TrialLog in
Avatar of Shandy
Shandy

asked on

MSHFlexiGird. How To Add Columns At Runtime

I am using a MSHFlexiGrid to which I am allocating a recordset at run time. I don't want to display all the fields returned from the recordset in the MSHFlexiGrid but want to select which ones to display at runtime. How do I do this?
Avatar of jayaraghu
jayaraghu

HI,
you can just assign the field name to the grids cell.
for example,
if your query is
strsql="select * from StudentsTable"
set recordset=...

the table contains 5 fields, namely
studentid, studentname, studentDOB, studentcourse, studentgrade.

you want to display studentid and studentname in the grid.

for row=1 to recordset.recordcount-1
for col = 0 to 1
msflexgrid1.textmatrix(row,col)=recordset(col)
next col
next row

i hope this is what u expect.
good luck
JayaRaghu
Avatar of Shandy

ASKER

Not quite what I was after. I want to bind the MSHFlexGrid at runtime to a recordset and then only display certain columns/fields from the recordset in the MSHFlexGrid. I want the MSHFlexGrid to populate itself from the datasource I set at runtime (which it does), not assign field values manually to the MSHFlexGrid.
Ok say your recordset will retrieve 100 records at once. But you want only to show 10 at first and when click next load the next 10 ? There is something called "Paging" Set the cachsize of recordset = to 10 then use pagecount property and in a loop you move though the records. Post your reply if this what you need i will give an example.
Avatar of Shandy

ASKER

I'm afraid I'm not explaining this very well.

Try this example.
I want to use a recordset containing the fields:
forename, surname, Identity Number
I want to bind the MSHFlexGrid to this recordset at run time but only display forename and surname. By default it seems to display all 3 fields.

I know I could set up 2 separate recordsets but it just seemed a waste of resource if I could get the MSHFlexGrid to run off a recordset I already had open.
ASKER CERTIFIED SOLUTION
Avatar of mfclaes
mfclaes

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
Lets say you have 3 fields in your recordset namely f1,f2 and f3
and you don't want to display the field f2
So you will query the database like this
"select f1,f3,f2 from table"

and you will set the flexgrids colms as this
MSFlexGrid1.Cols = 2
so the last column is removed from display. So make sure to get the fields which you don't want to diaply at the last.


Hope it will help.
Avatar of Shandy

ASKER

Setting the width to 0 works. Obvious as soon as you pointed it out to me!
Thanks