Style.Reset does not seem to reset border

4 posts, 1 answers
  1. Ken
    Ken avatar
    10 posts
    Member since:
    Sep 2011

    Posted 23 Jan 2012 Link to this post

    It seems that Style.Reset() doesn't truly reset everything.  Code is below, results are attached.  Notice the black borders on the top two rows.  The value in the have columns for both of those rows was 0, then via code (UI technically), the number is updated to the same as the need column, going from a red border to the black border.  The third row down which appears as I would like it always had have > need, so it was never changed, and has the defaults.

    And while I have your attention I have two other related questions:
    1) Is there a better way to access the style element of a cell than this?
                GridViewCellInfo haveCell = e.RowElement.RowInfo.Cells["HaveColumn"];

    2) I just wanted a simple 2 pixel red border...I've seen conflicting information in the forums as to what's really required.  The smallest set of properties I found that would work are in the code below.  That seems like an awful lot of work to put a 2 pixel red border in place.  Is what I have the best approach?

            private void RequirementsGrid_RowFormatting(object sender, RowFormattingEventArgs e)
            {
                GridViewCellInfo haveCell = e.RowElement.RowInfo.Cells["HaveColumn"];

                int? need = (int?)e.RowElement.RowInfo.Cells["NeedColumn"].Value;
                int have = 0;
                if (haveCell.Value != null)
                    int.TryParse(haveCell.Value.ToString(), out have);

                if (have < need)
                {
                    haveCell.Style.CustomizeBorder = true;
                    haveCell.Style.BorderColor = Color.Red;
                    haveCell.Style.BorderGradientStyle = GradientStyles.Solid;
                    haveCell.Style.BorderBoxStyle = BorderBoxStyle.SingleBorder;
                    haveCell.Style.BorderWidth = 2;
                }
                else
                {
                    haveCell.Style.Reset();
                }
            }

    Thanks!
  2. Answer
    Jack
    Admin
    Jack avatar
    2333 posts

    Posted 26 Jan 2012 Link to this post

    Hello Ken,

    There is a better approach in this scenario. You can handle the CellFormatting event and customize the cell element directly. Please consider the following code:
    void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
    {
        GridDataCellElement haveCell = e.CellElement as GridDataCellElement;
        if (haveCell != null && haveCell.ColumnInfo.Name == "HaveColumn")
        {
            int? need = (int?)e.Row.Cells["NeedColumn"].Value;
            int have = 0;
            if (haveCell.Value != null)
                int.TryParse(haveCell.Value.ToString(), out have);
     
            if (have < need)
            {
                haveCell.DrawBorder = true;
                haveCell.BorderColor = Color.Red;
                haveCell.BorderGradientStyle = GradientStyles.Solid;
                haveCell.BorderBoxStyle = BorderBoxStyle.SingleBorder;
                haveCell.BorderWidth = 2;
                return;
            }
        }
        haveCell.ResetValue(LightVisualElement.DrawBorderProperty, ValueResetFlags.Local);
        haveCell.ResetValue(LightVisualElement.BorderColorProperty, ValueResetFlags.Local);
        haveCell.ResetValue(LightVisualElement.BorderGradientStyleProperty, ValueResetFlags.Local);
        haveCell.ResetValue(LightVisualElement.BorderBoxStyleProperty, ValueResetFlags.Local);
        haveCell.ResetValue(LightVisualElement.BorderWidthProperty, ValueResetFlags.Local);
    }

    Regarding the Reset method, I managed to reproduce the issue and we will address it in our upcoming release in February. Thank you for bringing our attention to it. I updated also your Telerik points.

    I hope this helps. If you have further questions, do not hesitate to contact us.
     
    Greetings,
    Jack
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

  3. Ken
    Ken avatar
    10 posts
    Member since:
    Sep 2011

    Posted 02 Feb 2012 Link to this post

    The temporary fix works well.  I also should mention I tried to use the following as well and it doesn't work:
     e.CellElement.ResetStyleSettings(true);

    I assume it's the same root cause and would likely be fixed, but I thought it couldn't hurt to bring it to your attention to be sure.
  4. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 03 Feb 2012 Link to this post

    Hello Ken,

    I am glad I could help. Regarding the ResetStyleSettings method, it is used internally and it resets only settings set through our theming mechanism. In your scenario you have to reset property settings by calling the ResetValue method with ValueResetFlags.Local as argument as mentioned in this article.

    Feel free to contact us, If you have other questions.
     
    All the best,
    Jack
    the Telerik team

    SP1 of Q3’11 of RadControls for WinForms is available for download (see what's new).

Back to Top