How can I make conditional formatting read-only?

4 posts, 1 answers
  1. Chris
    Chris avatar
    5 posts
    Member since:
    Sep 2014

    Posted 23 Sep 2014 Link to this post

    We have a data grid view which we would like to apply a few conditional rules programmatically. We would still like the end user to be able to add their own conditional formatting rules, however; we would like to block them from deleting the rules that we added via code. Please see the attached screenshot for an example. How would I go about doing this?

    For my first attempt I subscribed to the the ConditionalFormattingObjectList.CollectionChanging event. The problem is that the Action received in this event is all of type Reset first, Add second. Basically the ConditionalFormattingForm is first clearing the collection and then re-adding the all the conditions. Additionally, when you cancel the collection changing the UI still reflects the changes even though you have canceled the event in the underlying collection. Should I be using a different event. Perhaps one on the ConditionalFormattingForm itself?

    Thank you,
    -Chris
  2. Answer
    George
    Admin
    George avatar
    500 posts

    Posted 26 Sep 2014 Link to this post

    Hello Chris,

    Thank you for writing.

    In this case it appears to me that the best approach would be to disable the Remove button instead of canceling events. You can subscribe to the SelectedIndexChanged event of the RadListControl in the CondtiionalFormattingForm:
    void Grid_ConditionalFormattingFormShown(object sender, EventArgs e)
    {
        ConditionalFormattingForm form = sender as ConditionalFormattingForm;
        var list = form.Controls["radListBoxConditions"] as RadListControl;
        var removeButtom = form.Controls["radButtonRemove"] as RadButton;
        list.SelectedIndexChanged += (s, ev) =>
            {
                var item = list.Items[ev.Position].Value;
                if (true) //determine whether the item was added by you
                {
                    removeButtom.Enabled = false;
                }
                else
                {
                    removeButtom.Enabled = true;
                }
            };
    }

    Let me know if you have other questions or if this approach is not suitable for your scenario.

    Regards,
    George
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chris
    Chris avatar
    5 posts
    Member since:
    Sep 2014

    Posted 29 Sep 2014 in reply to George Link to this post

    Thanks George,

    This is exactly what we needed.

    As a side note the Telerik.WinControls.UI.ConditionalFormattingForm.ColumnFormattingInfo type is not visible so I used reflection to access the Formatting Object.

    var item = list.Items[ev.Position].Value;
    var propertyInfo = item.GetType().GetProperty("FormattingObject");
    var formattingObject = propertyInfo.GetValue(item, null) as ConditionalFormattingObject;
    if (CoreConditions.Contains(formattingObject.Name)) //determine whether the item was added by you
    {
         removeButtom.Enabled = false;
    }
    else
    {
         removeButtom.Enabled = true;
    }

    Thanks again,
    Chris
  5. George
    Admin
    George avatar
    500 posts

    Posted 02 Oct 2014 Link to this post

    Hi Chris,

    I am glad that you found a solution for the matter. 

    Do not hesitate to let me know, should you require further assistance.

    Regards,
    George
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top