Sorting Data in a grid using TFDTable

668 views Asked by At

I have a TFDTable the is connected to a TGrid using LiveBindings and the data displays sorted by the indexes in the table itself. I want to be able to change the sort order by clicking on the header of the grid. Here is what I have done so far:

void __fastcall TmainFrm::Grid7HeaderClick(TColumn *Column)
{
    if(IBS_EntityTable->IndexName == Column->Header)
        return; // if it is being sorted by the same column, don't do anything
    try
    {
        TFDIndex* pIndex;

        IBS_EntityTable->Indexes->BeginUpdate();
        IBS_EntityTable->Indexes->Clear();
        pIndex = IBS_EntityTable->Indexes->Add();
        pIndex->Name = Column->Header;
        pIndex->Fields = Column->Header;
        pIndex->Active = true;
        IBS_EntityTable->IndexName = pIndex->Name;
    }
    __finally
    {
      IBS_EntityTable->Indexes->EndUpdate();
      IBS_EntityTable->Refresh();
    }
}

but the sort order does not change. In fact the only data that does change is the selected row. What am I doing wrong?

Thank you
Sam

0

There are 0 answers