I want to sort the grid. I created a memory table and bound it to the grid as a data source. I am inserting data into a memory table from an nxQuery object. For sorting, I have to add an index also to the memory table.
This is adding and adding an index, which is in the form of create event
nxMemTable1.IndexDefs.Clear; nxMemTable1.FieldDefs.Clear; nxMemTable1.FieldDefs.Add('packpatientid', ftInteger, 0, False); nxMemTable1.FieldDefs.Add('firstname', ftString, 10, False); nxMemTable1.FieldDefs.Add('lastname', ftString, 10, False); while not nxQuery1.EOF do begin nxMemTable1.Append; nxMemTable1.FieldByName('packpatientid').AsInteger := nxQuery1packpatientid.AsInteger; nxMemTable1.FieldByName('firstname').AsString := nxQuery1firstname.AsString; nxMemTable1.FieldByName('lastname').AsString := nxQuery1lastname.AsString; nxMemTable1.Post; end;
and this is the code I'm trying to sort the memory table
procedure TForm1.Button2Click(Sender: TObject); begin nxMemTable1.IndexFieldNames := 'firstname'; end;
but it does not work. when I click the button, it says: "There is no index for the field" firstname ""
source share