This is a migrated thread and some comments may be shown as answers.

How can I make conditional formatting read-only?

3 Answers 102 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 23 Sep 2014, 09:37 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
George
Telerik team
answered on 26 Sep 2014, 08:37 AM
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.
 
0
Chris
Top achievements
Rank 1
answered on 29 Sep 2014, 01:57 PM
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
0
George
Telerik team
answered on 02 Oct 2014, 08:24 AM
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.
 
Tags
GridView
Asked by
Chris
Top achievements
Rank 1
Answers by
George
Telerik team
Chris
Top achievements
Rank 1
Share this question
or