Editing PercentCellType, also using Minium- MaximumValue

Posted by: pontius on 8 September 2017, 2:59 pm EST

  • Posted 8 September 2017, 2:59 pm EST

    Hi,

    I have two cells of PercentCellType both containing numbers, one upper value one lower value.
    The value in the upper cell must always be higher than the value in the lower cell.

    E.g.:
    upper cell 70%
    lower cell 60%

    The MinimumValue of the upper cell is the value of the lower cell.
    So it can not occur that the user reduces the value of the upper cell lower than 60% in the axample above.

    When editing the lower cell I have to adjust the MinimumValue of the upper cell. E.g. I edit 65% in the lower cell
    then the MinimumValue of the upper cell must also be 65%.

    When I use the SpinButton I can handle the EditChange event to adjust the Minimum-/MaximumValues of the corresponding other cell.
    That works fine.

    However when the user enters the editable cell itself (instead of using the SpinButton) the event EditChange may occur with a value that is
    lower then the MinimumValue I have set (and vice versa).

    Does this mean that I must forbid editing in cell itself in order to get allowed values (greater than minimum and lower than maximu)?

    Or can I trigger on a different event than EditChange in order to get allowed values only?

    Regards,
    Pontius

  • Replied 8 September 2017, 2:59 pm EST

    Hi bobyo,

    I have a PercentCellType-derived MyPercentCellType with a Property NumberOfDigits:

    public class MyPercentCellType : FarPoint.Win.Spread.CellType.PercentCellType
    {
        private static int ms_NumberOfDigits = 2;

        private static Dictionary ms_DecimalPlaces = new Dictionary()
        {
            {1, 0.1F},
            {2, 0.01F},
            {3, 0.001F},
            {4, 0.0001F},
            {5, 0.00001F},
        };

        public int NumberOfDigits
        {
            set
            {
                if (ms_DecimalPlaces.ContainsKey(value))
                {
                    ms_NumberOfDigits = value;
                    DecimalPlaces = ms_NumberOfDigits;
                    SpinDecimalIncrement = ms_DecimalPlaces[ms_NumberOfDigits];
                }
            }
        }
    }

    In my SheetView-derived class MySheetView I have also a Property NumberOfDigits:

    public int NumberOfDigits
    {
        set
        {
            for (int i = 0; i < RowCount; i++)
            {
                for (int j = 0; j < ColumnCount; j++)
                {
                    if (Cells.Get(i, j).CellType is MyPercentCellType)
                    {
                        (Cells.Get(i, j).CellType as MyPercentCellType).NumberOfDigits = value;
                    }
                }
            }
        }
    }

    Using this Property leads to the situation that the DecimalPlaces get in effect after hovering with the mouse over the cell.

    Regards,
    Pontius

  • Replied 8 September 2017, 2:59 pm EST

    Hi,

    I found out that the EditModeOff event just comes at the right moment und does what I want rather than the EditChange event.

    My code looks like:

    private void _Spread_EditModeOff(object sender, EventArgs e)
    {
        int row = ((FpSpread)sender).ActiveSheet.ActiveRow.Index;
        int col = ((FpSpread)sender).ActiveSheet.ActiveColumn.Index;

        double percentage = (double)(m_MySheet.Cells.Get(row, col).Value);
                
        SetMinMaxRelatedCell(percentage, row, col);
    }

    Thanks and regards,
    Pontius

  • Replied 8 September 2017, 2:59 pm EST

    Hello,

    It is good to know that your issue has been resolved. Please let me know if you have any queries further.

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 2:59 pm EST

    Hi,

    when I set the DecimalPlaces the cell doesn't change until the user hovers with the mouse over it.

    I would like the cell to change instantly. How can I trigger this?

    Regards,
    Pontius

  • Replied 8 September 2017, 2:59 pm EST

    Pontius,

    I could not reproduce the issue that you are encountering.

    I tested code that created a new percent cell. For example...

    PercentCellType cellType = new PercentCellType();
    cellType.DecimalPlaces = 2;
    fpSpread1.Sheets[0].Cells[0, 0].CellType = cellType;

    I tested code that modified a existing percent cell. For example...

    PercentCellType oldCellType = fpSpread1.Sheets[0].Cells[0, 0].CellType as PercentCellType;
    PercentCellType newCellType = oldCellType.Clone() as PercentCellType;
    if (oldCellType.DecimalPlaces == 1)
    {
        newCellType.DecimalPlaces = 2;
    }
    else
    {
        newCellType.DecimalPlaces = 1;
    }
    fpSpread1.Sheets[0].Cells[0, 0].CellType = newCellType;

    In both cases, the cell was immediately repainted using the assigned DecimalPlaces.

    Could you provide an example of the code you are using to assign DecimalPlaces?

  • Replied 8 September 2017, 2:59 pm EST

    Hello,

    I tried using the code provided by you but I am not able to replicate the issue using the same, I would request you to provide me a sample application depicting your issue so that I can replicate the issue at my end and debug it further.

    Thanks,

    Manpreet Kaur

  • Replied 8 September 2017, 2:59 pm EST

    Pontius,

    The cell type objects are designed to be shared across cells. You create the cell type object, set properties on the cell type object, and assign the cell type object to one or more cells. Once you assign the cell type object to a cell, you should not modify the cell type object. The cell type object has no change event to notify the cell of changes that require a repaint. This is by design to avoid performance hit of having every cell listen to the its cell type object. If you need to modify a cell's existing cell type then you should clone the existing cell type, modify the clone, assign the modified clone to the cell. Refer to the example in my earlier post where I modified an existing percent cell.

  • Replied 8 September 2017, 2:59 pm EST

    Hi Manpreet,

    I have created a sample application for you.

    It seems that after changing the DecimalPlaces the changes in the GUI get in effect after the mouse has hovered over the cell and then the cell lost the focus again.

    Regards,
    Pontius


    2012/08/DecimalNumber.zip
  • Replied 8 September 2017, 2:59 pm EST

    Hi,

    ok thanks. I have done it with cloning the CellType and it works.

    Regards,
    Pontius

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels