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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting table data that fills a grid

Status
Not open for further replies.

hallm

Programmer
Jun 11, 2000
159
US
I've got a grid control on the first tab (page) of my form that I use to select the records. I've got it set up so that I can click on the header of each column and change the sort order of that column.

What I'm wanting is when the form is first opened the grid is sorted by customer name.

SET ORDER TO customer_name ASCENDING

My code for the header is
If nShift = 2
SET ORDER TO Med_rec_id DESCENDING
ELSE
SET ORDER TO Med_rec_id ASCENDING
ENDIF

GO TOP
THISFORM.Refresh

Where is the best place for my initial sort order code to go, I'm only wanting it to sort that way when the form is first opened and retain the header sorts after the form is refreshed.

Every where I've stuck the code so far has sorted by customer when the form is opened, but will not retain the header sorts after a form refresh.

Any suggestions?

Marion

 
I wouldn't put the code in the refresh event of the form as this can fire multiple times depending on your application and code. Just put the initial sort in the init event of the form (that's plenty soon enough and well after the grid is initialized). Another option is to use some of the DE events or the order property, but for simplicity's sake I would just use the form's init event.

boyd.gif

 
Just put the initial sort in the init event of the form
That'll set the initial sort order but I understood that that order was being lost during later processing. I accept that Refresh can be wasteful because it fires many times but at least it will ensure that the sort order is maintained.

I know in my heart that the true answer would be to dig deep and determine just when and why the sort order is being lost but I was offering a quick and dirty solution.

Geoff Franklin
 
After playing a good bit last night, I was able to get the form to do what I want it to do. I may have a good bit of wasteful code.

I wanted the grid to be initially sorted by name, so I put name as the ChildOrder for the grid.

Each header of the grid has the code in the above post to sort by that column and refresh.

Each page tab has a refresh to refresh the data when you change the page. I don't know why that is needed, because the grid click has a refresh on it also. But it didn't refresh the other pages without it.

It is working though.

Thanks,
Marion
 
Hi Marion,

If a page isn't active/visible, it's controls (and grids)are not refreshed if you don't do so explicit.
This saves time, so why don't you just refresh the grid in the activate event of each page?

Initial order is best set in the grid's init, not in it's childorder property. Thats for having realtions between parent and child tables...

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top