HomeActive Query Builder - HowTos and TroubleshootingUser Interface CustomizationHow to implement custom sorting of the fields inside datasources?

1.4. How to implement custom sorting of the fields inside datasources?

The following code sorts fields by description, but places fields with empty descriptions to the bottom.

private void queryBuilder1_CustomizeDatasourceFieldList(QueryBuilder queryBuilder, DataSource datasource, MetadataFieldList fieldList)
{
       fieldList.Sort(new SortFieldsByDescriptionComparer());
}

private class SortFieldsByDescriptionComparer: IComparer<MetadataCollectionItemBase>
{
       int IComparer<MetadataCollectionItemBase>.Compare(MetadataCollectionItemBase qn1, MetadataCollectionItemBase qn2)
       {
               MetadataField f1 = (MetadataField) qn1;
               MetadataField f2 = (MetadataField) qn2;

               int result = String.Compare(f1.ShortDescription, f2.ShortDescription, true);

               if (result == 0)
               {
                       result = String.Compare(f1.AltName, f2.AltName, true);

                       if (result == 0)
                       {
                               result = String.Compare(f1.NameStr, f2.NameStr, true);
                       }
               }
               return result;
       }
}

This page was: Helpful | Not Helpful