Showing posts with label grid. Show all posts
Showing posts with label grid. Show all posts

Saturday, December 11, 2021

Multiple enum values selection in forms and tables

Previously I posted three supporting functions to work with multiple enum values selection. Now, let's see how they can be used in real scenarios.

With these functions you can easily expose enum values in selection lists and then save the user selection in tables.

Enum lists in a form

Check first how to show two grids in a form; so that the user could move enum values from one to another.




[Form]
public class SysPolicyTypesOneCompanyActiveOnly extends FormRun
{

    private Map                 policyTypes = wzhTest::createMapForEnum(enumStr(SysPolicyTypeEnum));
    private SysPolicyTypeEnum   type;
 
    private void resetSysPolicyTypeListPanel()
    {
        SysPolicyTypeAvailableGrid.deleteRows(0, SysPolicyTypeAvailableGrid.rows());
        SysPolicyTypeEnabledGrid.deleteRows(0, SysPolicyTypeEnabledGrid.rows());

        var mapEnumerator = policyTypes.getEnumerator();
        while (mapEnumerator.moveNext())
        {
            type        = mapEnumerator.currentKey();
            
            if (SysPolicyTypesOneCompanyActiveOnly::exist(type))
            {
                this.addRowForTypes(SysPolicyTypeEnabledGrid, type);
            }
            else
            {
                this.addRowForTypes(SysPolicyTypeAvailableGrid, type);
            }
        }

        SysPolicyTypeAvailableGrid.row(SysPolicyTypeAvailableGrid.rows() ? 1 : 0);
        SysPolicyTypeEnabledGrid.row(SysPolicyTypeEnabledGrid.rows() ? 1 : 0);
    }

    private int addRowForTypes(FormTableControl _table, SysPolicyTypeEnum _type)
    {
        int i;
        // Insert it into the data set in sorted order.
        for (i = _table.rows(); i >= 1; i--)
        {
            SysPolicyTypeEnum typeIdTmp = _table.cell(1, i).data();
            
            if (strCmp(enum2Str(typeIdTmp), enum2Str(_type)) < 0)
            {
                // We need to insert after the current item.
                break;
            }
        }

        // Insert the new item, i is equal to the index of the item we need to insert after.
        _table.insertRows(i, 1);
        _table.cell(1, i + 1).data(_type);

        return i + 1;
    }
...
}

Multiple enum values in a table

In order to save user's selection of particular Enum values in a table, you can add a string type field there. 

The rest is to convert these selected values from string to a list or a container to present them in a form.

Say, we need to let the user to select particular FiscalPeriodStatus values.



First, we add a new string field FiscalPeriodStatusSelection to our table.


We can show the currently saved selection via a display method

    /// <summary>
    /// Returns Fiscal period statuses string values
    /// </summary>
    /// <param name = "_parm">container</param>
    /// <returns>string values of selected period statuses</returns>
    [SysClientCacheDataMethodAttribute(true)]
    public display LedgerExchAdjFiscalPeriodStatusSelection fiscalPeriodStatusSelectionDisp()
    {
        return wzhTest::enumValuesStr2EnumStrStr(this.FiscalPeriodStatusSelection, enumName2Id(enumStr(FiscalPeriodStatus)));
}

And updates this field via AnotherClass which treats the user's selection (in a form, for example)

    this.FiscalPeriodStatusSelection = con2Str(AnotherClass.getFiscalPeriodStatusSelectionCont(), wzhTest::ContSeparator);

    /// <summary>
    /// Gets FiscalPeriodStatus selection as a container
    /// </summary>
    /// <returns>container</returns>
    public container getFiscalPeriodStatusSelectionCont()
    {
        container                               cont;
        
        while (...)
        {
            cont += SomeBufferOrList.FiscalPeriodStatus;
        }
                
        return cont;
    }

Tuesday, March 26, 2019

How to get number of rows loaded in a grid

In fact we can use numberOfRowsLoaded on a linked form data source; however, it shows the number of those cached only.

So, if you are editing row number 28, for example, and then call ExecuteQuery() on the data source, you will probably get a lower number of rows loaded in the grid yet, say, 19.

In order to get the right number, you should use the aforementioned method together with allRowsLoaded() one.

public int myNumberOfRowsLoaded()
{
    int myNumOfRec;
    int myCounter;

    myNumOfRec = PSAActivityEstimates_DS.numberOfRowsLoaded();
    // nothing to load yet
    if(!myNumOfRec)
    {
        return myNumOfRec;
    }
    // so far we numbered those lines cached only
    while(!PSAActivityEstimates_DS.allRowsLoaded())
    {
        // so let's move it on until the end of loading
        PSAActivityEstimates_DS.setPosition(myNumOfRec);
        PSAActivityEstimates_DS.getNext();
        // just to avoid never ending adventure
        if(myCounter>1000)
        {
            break;
        }
        myCounter++;
        // get the number for the next iteration
        myNumOfRec = PSAActivityEstimates_DS.numberOfRowsLoaded();
    }
    // now all numberOfRowsLoaded() calls will return the correct number of rows in grids
    myNumOfRec = PSAActivityEstimates_DS.numberOfRowsLoaded();

    return myNumOfRec;
}

Saturday, January 12, 2019

Date time range

Just for my records

 (dayRange(-5, 0))

 Taken from here

Thank you Martin!

Tuesday, October 21, 2008

Images on Form and Thumbnails in Grid

It is not a very complicated topic when it comes to show pictures on a form with Window control, but showing them in a grid caused some difficulties to me.

Here is the very simple project Images&ThumbnailsInGrid that will show you the way if are a little bit lost.


You can construct Image objects from the following file types:
  • Raster (bitmap) formats - .bmp, .gif, .jpg, .png, .tiff, and .exif
  • Vector formats - .emf and .wmf

By the way, do not forget about MSDN: