Link to home
Start Free TrialLog in
Avatar of MikeP090797
MikeP090797

asked on

Sorting DBGrid

I need the records in a DBGrid to be sorted by a spicific field. I need that the records will reposition according to the sort order every time the user updates the field. How that can be done?
Avatar of ChrisLewis
ChrisLewis

I think some one jsut asked this question, it might have even been you.

  Basically, if you are changing sort fields in the DBGrid, you have to refresh the query the DBGrid is based on to get the new sort order.  You cannot just "move" the row to the new position, you will actually have to re-retrieve your rows.  

  I know this is not what you want to here, but with DBgrid, you are limited to it's functionality
Sorry, hit the submit button too early.

Anyway, continuing,

If you want to try, you might be able to do something with an unbound grid, and deal with it that way.  

Basically, you would retrieve your information, and load up a grid.

When the user selects a row, either pop a text box over the row for editing.  (note that you won't be editing the row directly)

you could then determine where in the grid to move the row to.  
Unfortunately, there is no INSERT command for a grid, so you'd have to move to the new row, move everything down 1 row, write the changed row in, move to the changed row, and move everything up one.

Doesn't sound nice.

Chris
Avatar of MikeP090797

ASKER

Re-retreiving the reocrds each time would be too slow. The RecordSource is a table. I tried to set an index to the table, but the first row disappears every time i add a row thta according to the sort order isn't the last one. What might be the reason for that?
ASKER CERTIFIED SOLUTION
Avatar of mrmick
mrmick

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
This is not what i need. I need the records to be sorted every time the user updates the field that the table is sorted now. Is there anyway of doing that without reloading the whole table again?
Mike, the dbgrid doesn't have a method that automatically performs this for you.

DBGrid was written by APEX for Microsoft.  As a service to DBGrid users, APEX provides a free on-line help file that contains a wealth of detailed information not found in the Visual Basic documentation, with accompanying tutorial projects. This complete reference is the definitive source for information on DBGrid, and is a "must-have" for any DBGrid user. To download a copy, visit the APEX web site at http://www.apexsc.com.

I believe you can download the True DBGrid upgrade for free.