Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Now I really DO have a problem, - Sorting

Now I really DO have a problem, - Sorting

Now I really DO have a problem, - Sorting

I have a MyDataModule. In it I have MyConnection1, a query and this is a second Query.

I have a MyDataSource2 and a MyQuery2. On the form I'm busy with, there is a ListBox, populated with the fields that I want to sort on. The idea is, the user selects a field and then the code (below) displays the sorted List in a dbGrid. It works fine, with ine teeny exception, It doesn't sort on anything other than the itemno (which is the Primary Key.

I have the following code

Procedure DoSort;
QString : String;
dmFiles.MyQuery2.Active := True;
dmFiles.MyQuery2.Close;{close the query}
QString := '';
//assign new SQL expression
dmFiles.MyQuery2.SQL.Add ('Select itemno, name, code1, code2,' +
'vendor, type, rating, tested ');
dmFiles.MyQuery2.SQL.Add('from files4 ');
dmFilms.MyQuery2.SQL.Add ('order by ');
QString := SortForm.SortSelect.Items [SortForm.SortSelect.ItemIndex];
dmFilms.MyQuery2.SQL.Add (QString);
dmFilms.MyQuery2.Open; {open query + display data}

I just know I should see the answer, but I can't. I'm sure someone else can!

RE: Now I really DO have a problem, - Sorting

If you're wanting to copy an item out of a ListBox into a string, you have to do something like this:


if ListBox1.ItemIndex > -1 then  // exception: Nothing is selected.
  Label1.Caption := ListBox1.Items.Strings[ListBox1.ItemIndex]; 

I'm guessing your code is assigning some garbage to QString and it's just ignoring it when it comes to the statement.

RE: Now I really DO have a problem, - Sorting

Also - have a look to see if your grid supports sorting and that perhaps it is re-sorting your result set after you've collected the data.

RE: Now I really DO have a problem, - Sorting

It wasn't QString. I put it on the Watch list and stepped through. The value was correct.

I was using the standard DBGrid from XE7. I've tried a dozen different things but still no sort.

I did solve the problem. Cheating, I know, but at 80. I'm allowed to cheat!

I found a dbGrid that DOES support sorting so I got it working eventually.

Thanks for trying anyhow

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close