Spread silverlight doesn't behave as excel for percentage format

Posted by: kamalkishore on 10 September 2017, 10:57 am EST

  • Posted 10 September 2017, 10:57 am EST

    Hello,

    Please check this link:

    http://demo.componentone.com/spread/controlexplorer/#Formatter/Formatter

    go to cell in  line number 92 and third column i.e. Display and observe this cell. This cell is given percentage format. Punch number 10 in this cell and you will see value of the cell as 1000%. Check same thing in excel. Assign percentage format to any cell and then punch number 10 in that cell. Excel will show the value as 10%. What can be done to resolve this issue.

     

  • Replied 10 September 2017, 10:57 am EST

    Hello,

     

    That is what I mean. Think like, if I have an application where user enters values in cells and cells are formatted for percentage values, no user will enter % symbol, user will only enter value as they do in excel. I feel like spread should do this without asking users to punch % symbol.

  • Replied 10 September 2017, 10:57 am EST

    Any updates on this issue?

     Actually I tried to handle this thing in edit end event like below:

     gcSpread.ActiveSheet.Cells[e.Row, e.Column].Value = dblVal / 100;

     This code calls Edit_End event internally, and my application is crashing due to stack overflow. Let me know what should I do to resolve this case.

  • Replied 10 September 2017, 10:57 am EST

    any updates?
  • Replied 10 September 2017, 10:57 am EST

    kamalkishore,

    The difference is that Excel automatically inserts the percent symbol "%" when editting while Spread does not (i.e. in Excel you are entering 10% while in Spread you are entering 10 which is 1000%). If you manually add the percent symbol while editting in Spread then Spread gives the same value as Excel. If you manually remove the percent symbol while editting in Excel then Excel gives the same value as Spread.

  • Replied 10 September 2017, 10:57 am EST

    Sorry for late replay,
    It is possible to solve it by a little bit code in EditCellStarting event. Try this:

        public partial class MainPage : UserControl

        {

            public MainPage()

            {

                InitializeComponent();

                this.gcSpreadSheet1.EditStarting +=new System.EventHandler(gcSpreadSheet1_EditStarting);

                var sheet = this.gcSpreadSheet1.ActiveSheet;

                for (int i = 0; i < sheet.RowCount; i++)

                {

                    for (int j = 0; j < sheet.ColumnCount; j++)

                    {

                        sheet.SetValue(i, j, 0.55);

                        sheet[i, j].Formatter = new GeneralFormatter("0%");

                    }

                }

            }

            private void gcSpreadSheet1_EditStarting(object sender, EditCellStartingEventArgs e)

            {

                var text = this.gcSpreadSheet1.ActiveSheet.GetText(e.Row, e.Column);

                var editor = (this.gcSpreadSheet1.View.CellEditor as TextBox);

                editor.TextChanged -= new TextChangedEventHandler(editor_TextChanged);

                editor.Text = text;

                editor.TextChanged += new TextChangedEventHandler(editor_TextChanged);

            }


            void editor_TextChanged(object sender, TextChangedEventArgs e)

            {

                var editor = (sender as TextBox);

                if (editor!=null && !editor.Text.Contains("%") && !editor.Text.EndsWith("%"))

                {

                    editor.Text = editor.Text + "%";

                    editor.SelectionStart = editor.Text.Length - 1;

                }

            }

        } 

     

    Hope it could help 

  • Replied 10 September 2017, 10:57 am EST

    Thanks eric,

    its awesome

Need extra support?

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

Learn More

Forum Channels