How to sort currency on Currencies & Exchange Rates with default currency on top?

SOLVED

Hi all,

I need to sort the order of the currencies & exchange rates but with several important currencies such as EURO, Pound, and USD on top, while the other currencies (in the red circle) should be sorted alphabetically.

I have tried "Allow Sort" true but it will sort all of the currencies including Euro, Pound, USD. 

Any way to do it? Thank you.

  • +1
    verified answer

    The List and grid controls have a FixedDataSource property. You can create a List<T> where T is your currency record and populate it with the 'important' stuff. Then set that as the FixedDataSource and set the FixedDataSourceFirst property to true. That should get you somewhere close.

  • 0 in reply to Chris Burke

    thank you. will try it out

  • 0 in reply to Chris Burke

    Hi Chris, I have try this method but it is not consistent.

    the following is my code.

    private void SortExchangeRatesGrid()
    {
        List<long> syscurrenciesID = new List<long>();
        CurrencyISOCodes isos = CurrencyISOCodesFactory.Factory.CreateNew();
        
        Filters filters = new Filters();
        filters.LogicalOperator = Sage.Common.Data.LogicalOperator.Or;
        
        foreach (CurrencyISOCode c in isos)
        {
            if ( c.Code.Equals("EUR") || c.Code.Equals("GBP") || c.Code.Equals("USD") )
            {
                Filter f1 = new Filter(FinancialCurrency.FIELD_CURRENCYISOCODEDBKEY, c.SYSCurrencyISOCode);
                filters.Add(f1);
                syscurrenciesID.Add(c.SYSCurrencyISOCode);
            }
        }
        string syscurrenciesIDs = "'" + string.Join("','", syscurrenciesID) + "'";
        FinancialCurrencies fcs = exchangeRatesGrid.DataSource as FinancialCurrencies;
        FinancialCurrencies importantFC = fcs.Clone() as FinancialCurrencies;
        
        importantFC.Query.Filters.Add(filters);
        importantFC.Find();
        exchangeRatesGrid.FixedDataSource = importantFC;
        exchangeRatesGrid.FixedDataSourceFirst = true;
        exchangeRatesGrid.RefreshContents();
    }

    The currencies in the importantFC (EUR, USD, Pound Sterling) is repeated.

    Then I think it is repeated because the original DataSource of the grid still have the currency that I added to the FixedDataSource. So I filter the original DataSource.

    private void SortExchangeRatesGrid()
    {
        Logger.WriteLog("here in SortExchangeRatesGrid");
        List<long> syscurrenciesID = new List<long>();
        CurrencyISOCodes isos = CurrencyISOCodesFactory.Factory.CreateNew();
        
        Filters filters = new Filters();
        filters.LogicalOperator = Sage.Common.Data.LogicalOperator.Or;
        
        foreach (CurrencyISOCode c in isos)
        {
            if ( c.Code.Equals("EUR") || c.Code.Equals("GBP") || c.Code.Equals("USD") )
            {
                Filter f1 = new Filter(FinancialCurrency.FIELD_CURRENCYISOCODEDBKEY, c.SYSCurrencyISOCode);
                filters.Add(f1);
                syscurrenciesID.Add(c.SYSCurrencyISOCode);
            }
        }
        string syscurrenciesIDs = "'" + string.Join("','", syscurrenciesID) + "'";
        FinancialCurrencies fcs = exchangeRatesGrid.DataSource as FinancialCurrencies;
        FinancialCurrencies importantFC = fcs.Clone() as FinancialCurrencies;
        fcs.Query.FilterText = FinancialCurrency.FIELD_SYSCURRENCYISOCODEOBJECT + "ID" + " not in ("+syscurrenciesIDs+")";
        fcs.Find();
        exchangeRatesGrid.DataSource = fcs;
    
        importantFC.Query.Filters.Add(filters);
        importantFC.Find();
        exchangeRatesGrid.FixedDataSource = importantFC;
        exchangeRatesGrid.FixedDataSourceFirst = true;
        exchangeRatesGrid.RefreshContents();
    }

    There is no more repeated currencies.  

    However, on the "Settings" Tab, now the EUR, USD, and Pound Sterling is now missing. I am guessing it is taking reference from the DataSource of exchangeRatesGrid. 

    If I loop the grid to validate and hide specific currency with exchangeRatesGrid.Items[0].Visible = false; , the currency from the FixedDataSource will be hidden as well. 

    Is there anyway to hide specific currency from the exchangeRateGrid.DataSource? 

  • 0 in reply to murni

    I think I probably hadn't appreciated that you were doing this on the actual currency maintenance form (although it's obvious now if I look at your screenshot more closely).

    Yes, both the grid are bound to the Currencies collection of the CurrenciesCoordinator object - so not only will that mean both grids get filtered, it means that the stuff in the FixedDataSource is stuff that the coordinator no longer knows about, so it'll break.

    Different approach: extend the SYSCurrency table (it's called FinancialCurrency in the ObjectStore Builder schema) to add a field (Int16 will do) called something like 'SortIndex'. Then manually populate the SYSCurrencyX table so that all currencies have a sort index of 100, except for the important ones which you can number 0-2. Then add a column to the grid and set it so it has a width of zero. Then sort the grid by this column in your code. Theoretically (I've not tried it!) this should get the result you want.

  • 0 in reply to Chris Burke

    that is good idea too. thank you, will try it out