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

Now I really DO have a problem, - Sorting

Status
Not open for further replies.

Baldur3635

Technical User
Feb 15, 2010
26
BE
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;
var
QString : String;
begin
dmFiles.MyQuery2.Active := True;
dmFiles.MyQuery2.Close;{close the query}
QString := '';
//assign new SQL expression
dmFiles.MyQuery2.SQL.Clear;
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}
End;

I just know I should see the answer, but I can't. I'm sure someone else can!
 
If you're wanting to copy an item out of a ListBox into a string, you have to do something like this:
Code:
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.

 
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top