TMSFMXGrid1.SortIndexes.Clear; if CHmanmodontop.IsChecked then TMSFMXGrid1.SortIndexes.AddIndex(6, sdAscending); case CBsort.ItemIndex of 0: TMSFMXGrid1.SortIndexes.AddIndex(5, sdAscending); 1: TMSFMXGrid1.SortIndexes.AddIndex(1, sdAscending); 2: TMSFMXGrid1.SortIndexes.AddIndex(3, sdDescending); 3: TMSFMXGrid1.SortIndexes.AddIndex(3, sdAscending); end; if TMSFMXGrid1.SortIndexes.Count>0 then TMSFMXGrid1.SortIndexed;
this also gives memoryleaks:
TRowinfo, TDatalist, unicodestring x6, Unknown
And another error is that when sorting mutiple columns, the row in the grid does not select the right row in the clientdataset. (using livebindings).
Sorting needs to be applied on the dataset. Internally sorting is applied to the grid and not automatically on the dataset.
You can implement the OnCanSort event and set Allow to false, and based on the sort setting perform a manual sort on the dataset directly. The dataset will automatically refresh the grid in a sorted state.
We are able to reproduce the memory leak and are still investigating the cause for this issue.
the problem still exists. you can try it in an new project.
add a grid and a clientdataset add 2 fields to the clientdataset (string and integer) add 3 indexes to the clientdataset (field1, field2, field2 descending add a button and a combobox with 3 items add the following code
procedure TForm1.Button1Click(Sender: TObject); var i: Integer; begin ClientDataSet1.CreateDataSet; ClientDataSet1.Open; for i := 0 to 10 do ClientDataSet1.AppendRecord([inttostr(10-i)+'test',i]); end;
procedure TForm1.ComboBox1Change(Sender: TObject); begin TMSFMXGrid1.BeginUpdate; case ComboBox1.ItemIndex of 0:clientdataset1.IndexName:='index1'; 1:clientdataset1.IndexName:='index2'; 2:clientdataset1.IndexName:='index3'; end; TMSFMXGrid1.endUpdate; end;