FlexGrid for WinForms

Editor.Text picking up formatted vale, not cell data

  •  sunibla said 8 months, 1 week ago:

    FlexGrid v. 4.6.20122.698 on Windows 7, 64. The editor is picking up the formatted value from the cell and only allowing editing in the format. For instance:

    On a manually populated grid with a column of type decimal with a format of "#,##0″, the editor picks up the value 105 when the cell value is 105.25. Also, the user cannot edit a decimal.

    This is different that older version converting from and is corrupting data. For instance, if user clicks in a cell with value of 101.25 and but does not edit, the editor is converting that value to 105.

  •  Reema19p said 8 months, 1 week ago:

    Hello,

    The Format property for a Column gets or sets a string that specifies how to format the data on this column.
    Since, a decimal is not being specified in the format string the editor won’t let the user enter a decimal or any character which has not been specified in the format string.
    You may set the format string of the respective column to "#,##0.00″, to display a cell value in it upto 2 decimal places.

    Please refer to the following documentation link for more information on the same :

    http://helpcentral.componentone.com/nethelp/c1flexgrid/#!Documents/formattingacellwithd.htm

    Let me know if I missed something here.

    Regards,
    Reema

  •  sunibla said 8 months, 1 week ago:

    If this was only a mask edit restriction on the decimals, that might be OK, but this is different than earlier versions and the problem (major) is this: when the cell goes into edit mode, the editor picks up the displayed format AS THE VALUE. If the user then edits the value to something new, then there is no problem, but if the user does not edit the cell (e.g., just happened to click in it), then after moving to next cell, the old cell value would have been changed to the formatted value.

    For instance, I am showing decimal data without decimals (at client’s request since the numbers are large and the decimal values are irrelevant for display purposes, plus they take up more room). However, the decimal values are important, so when the user clicks in a cell with a value of say 2035.35 and clicks in the next cell, the editor has picked up 2035 and after edited has changed the value of the cell to 2035. This is a bug, period.

    Regardless of what the editor is masking or showing, the editor must maintain the value unless changed. There does not seem to be a separate value part of the editor. See your first net version on how this is supposed to work. Or look at Excel, when cells are formatted and you click in them and move on, the underlying values to not change to the formatted amount.

    Thanks.

  •  Reema19p said 8 months ago:

    Hello,

    This seems to be a bug.
    I have escalated the issue to the concerned team & will revert back to you as soon as I get any information from their side.

    Thanks for reporting it.

    Regards,
    Reema

  •  C1_BernardoC7p said 8 months ago:

    We have modified the FlexGrid so the original value is kept if the user doesn’t change the content of the editor. The change is in build 721. Thanks for the suggestion.

    But in situations like the one you describe, it might be better to turn off the formatted editing altogether, so the user can see/edit the full value. This can be accomplished with the following line:

    this.c1FlexGrid1.EditOptions &= ~C1.Win.C1FlexGrid.EditFlags.UseNumericEditor;

    Answer
  •  sunibla said 8 months ago:

    Thanks for quick fix. Original version would ignore the format on edit by default, but changing to numeric editor if fine.

  •  sunibla said 8 months ago:

    How do I get this build? Thanks.

  •  C1_BernardoC7p said 8 months ago:

    The latest build will be posted to our prerelease site in the next few days:

    http://prerelease.componentone.com/

    If you need it right away, let me know and I will post a copy for you (but I suggest waiting until our QA team has had a chance to sign off on it).

  •  sunibla said 7 months, 3 weeks ago:

    Bernardo: I have downloaded the pre-release and it fixes the value problem. Again, thanks for quick fix. However, I have come across a couple of anomalies (also apparently present in older version):

    1. If I use the numeric editor as you suggest above (this.c1FlexGrid1.EditOptions &= ~C1.Win.C1FlexGrid.EditFlags.UseNumericEditor;) to edit the cell’s values with the decimals, then although this allows edits of decimals, the numeric editor is firing the Start/Validate/After Edit events even when no edit, i.e., just tabbing through the fields is firing these events, or clicking in the field without editing is also firing them. This, I think, is a bug.

    I am working around by not using the numeric editor and just setting the grid’s Editor Style format to "0.0000″ to get the number of decimals I want to, and this is working.

    The field’s datatype is decimal.

    2. I am changing some cell styles to reflect various states of the data (e.g., formatting the forecolor to red on negative numbers, backcolors to various colors depending on the type of row ( rollup, calculation, etc) and setting the cellstle format to the format used by the column headers. Most of the cells are detail cells and using the Normal Style by default.

    Now, since my code on the detail cells after edit will change the cellstyle to the custom one on negative numbers, when the user changes to positive number, I have to reset the cellstyle to the normal style. Here is how I was handling detail cells in NET 1 version of your controls, and worked fine:

    for (int c = StartCol; c <= EndCol; c++)
    {
    if (Convert.ToDecimal(flexPlan[r, c]) < 0)
    {
    flexPlan.SetCellStyle(r, c, csNegative);
    }
    else
    {
    clsC = (ColInfo)flexPlan.Cols.UserData;
    if (clsC.RowCellInfo(r).Locked)
    {
    flexPlan.SetCellStyle(r, c, csLocked);
    }
    else
    {
    flexPlan.SetCellStyle(r, c, flexPlan.Styles.Normal);
    }
    }
    }

    Here I am directly setting the cellstyle to the Normal style when the cell’s value is positive (and not locked (an application specific setting). Now, I tab through to edit, all is fine, but if I edit a value, after leaving the edit, the display will show the exact format of the edit, rather than the format of the nomal style. So if My column format and Normal format is "#,##0″ and I edit to 5.25, the cell will display 5.25 after I leave rather than 5.

    I create a style on normal without any changes and assign it to the cell, then that works (or just assigning cellstyle to null where it would use normal), but directly assigning the built in styles doesn’t, which seems strange.

    By the way, I don’t suppose there is a build in way to display negative numbers without having to code this for every data change?

    Thanks.

  •  C1_BernardoC7p said 7 months, 3 weeks ago:

    Hi.

    I don’t see the events firing as you described. Can you send me a sample showing this?

    As for the conditional formatting, the best way to do that is using OwnerDraw to select the style based on the cell content. For example:

                // create styles for positive and negative values
                var csNeg = _flex.Styles.Add("Negative");
                csNeg.ForeColor = Color.DarkRed;
                csNeg.Format = "n2″;
                var csPos = _flex.Styles.Add("Positive");
                csPos.ForeColor = Color.DarkGreen;
                csPos.Format = "n2″;
    
                // apply conditional styles
                _flex.DrawMode = C1.Win.C1FlexGrid.DrawModeEnum.OwnerDraw;
                _flex.OwnerDrawCell += (s, e) =>
                    {
                        double d;
                        if (double.TryParse(e.Text, out d))
                        {
                            e.Style = d >= 0 ? csPos : csNeg;
                            e.Text = d.ToString(e.Style.Format);
                        }
                    };

    I hope this example is useful.

  •  sunibla said 7 months, 3 weeks ago:

    Attached is a sample project. The relevant line of code is in the load event of the form:

    flexTmp.EditOptions &= C1.Win.C1FlexGrid.EditFlags.UseNumericEditor;

    Run the code and tab through the cells, you should see the message displayed by AfterEdit event.

    Rem out the line and re-run, only an edit will fire the events as expected.

    Thanks for you code on owner draw, I will look at as opposed to how I am handling. A couple of questions, when does this event fire? For example, If you changes one cell, will it only fire on that cell or repaint everything? Also, will it fire when values of a cell are changed in code?

    Attachments:
    You must be logged in to view attched files.
  •  C1_BernardoC7p said 7 months, 3 weeks ago:

    Thanks, now I see what you mean.

    The problem is that the code is not setting the EditOptions property correctly.

    My suggestion was to set it thus:

    flexTmp.EditOptions &= ~C1.Win.C1FlexGrid.EditFlags.UseNumericEditor;

    This means "turn off the option UseNumericEditor".

    The code you sent is missing the binary negation (~):

    flexTmp.EditOptions &= C1.Win.C1FlexGrid.EditFlags.UseNumericEditor;

    This means "turn off all options except for UseNumericEditor". The result of this is you’re turning off the "EditOnRequest" option, which causes the grid to enter edit mode whenever the selection changes, which in turn causes StartEdit etc to fire.

    If you fix that one line by adding the missing "~", all should be well.

  •  C1_BernardoC7p said 7 months, 3 weeks ago:

    Thanks, now I see what you mean.

    The problem is that the code is not setting the EditOptions property correctly.

    My suggestion was to set it thus:

    flexTmp.EditOptions &= ~C1.Win.C1FlexGrid.EditFlags.UseNumericEditor;

    This means "turn off the option UseNumericEditor".

    The code you sent is missing the binary negation (~):

    flexTmp.EditOptions &= C1.Win.C1FlexGrid.EditFlags.UseNumericEditor;

    This means "turn off all options except for UseNumericEditor". The result of this is you’re turning off the "EditOnRequest" option, which causes the grid to enter edit mode whenever the selection changes, which in turn causes StartEdit etc to fire.

    If you fix that one line by adding the missing "~", all should be well.

  •  sunibla said 7 months, 3 weeks ago:

    OK, thanks. I misunderstood, I presumed that numeric editor was not on by default.

    If you can also answer my other questions on the OwnerDraw event, it would be much appreciated:

    Thanks for you code on owner draw, I will look at as opposed to how I am handling. A couple of questions, when does this event fire? For example, If you changes one cell, will it only fire on that cell or repaint everything? Also, will it fire when values of a cell are changed in code?

  •  C1_BernardoC7p said 7 months, 3 weeks ago:

    Hello.

    The OwnerDrawCell event fires whenever a cell needs to be painted, for any reason whatsoever. For example, when the cell value changes, when the cell is selected or de-selected, when it scrolls into view, etc.

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.