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

Save Conditional Formatting

12 Answers 245 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 14 Jun 2016, 08:35 PM
I've read several reasons why it's not built into the SaveLayout, but I still would like a way to save Conditional Formatting. How can I achieve this?

12 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 15 Jun 2016, 08:27 AM
Hi Paul,

Thank you for writing.

The conditional formatting is saved when the layout is saved, this should work out of the box. 

Let me know if I can assist you further.

Regards,
Dimitar
Telerik
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Victor
Top achievements
Rank 2
answered on 10 Apr 2017, 01:51 PM

Hi,

If you want to save your gridview in the Property Builder, there is an option to exclude everythnig except the conditional formatting.

Is this (saving only the cond. format xml) also possible programmatically : I would like to have one company wide Cond. Form. for all the users. The rest of the layout of the grids are pure individual.

 

Hope to hearing from you soon

Victor

0
Hristo
Telerik team
answered on 11 Apr 2017, 12:57 PM
Hello Victor,

Thank you for writing.

The conditional formatting objects are serialized and this is the default behavior. It can be customized by accessing the SerializationMetadata collection: http://docs.telerik.com/devtools/winforms/gridview/save-and-load-layout/advanced.

In case you need further assistance please provide me with more details about your actual scenario.

I hope this helps.

Regards,
Hristo
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Victor
Top achievements
Rank 2
answered on 18 Apr 2017, 07:45 AM

Hello Hristo,

I the attached picture you can see what I am trying to achieve : Personal settings per user per radgridview (that works fine), but a corporate standard XML file containing the settings for the conditional formatting.

I have looked at the documentation but it does not states the metadata keywords needed for the conditonal formats. Can you supply me with these?

And a second question on de save/loadXML

If a grid changes (column added e.g.), the saved XML does not contain this column. That is logical. Is there a way without deleting the old XML (with all the usersettings) first to add this column in de xml file?

 

hope to hear from you soon

Kind regards

Victor

0
Dimitar
Telerik team
answered on 18 Apr 2017, 01:31 PM
Hello Victor,

Thank you for writing back.

Here are the required properties for saving the conditional formatting:
private void radButton1_Click(object sender, EventArgs e)
{
    radGridView1.XmlSerializationInfo.DisregardOriginalSerializationVisibility = true;
    radGridView1.XmlSerializationInfo.SerializationMetadata.Clear();
    radGridView1.XmlSerializationInfo.SerializeDefaultValues = true;
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(RadGridView), "MasterTemplate", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewTemplate), "Columns", DesignerSerializationVisibilityAttribute.Content);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "Name", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "HeaderText", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "FieldName", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn), "ConditionalFormattingObjectList", new DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content));
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "Name", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "ConditionType", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "TValue1", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "TValue2", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "RowBackColor", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "RowForeColor", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "CellForeColor", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "CellBackColor", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "CellFont", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "RowFont", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "ApplyToRow", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "ApplyOnSelectedRows", DesignerSerializationVisibilityAttribute.Visible);
    radGridView1.SaveLayout(@"D:\Formatting.xml");
 
}

If you want to add new columns you will need to add them after the layout is initially loaded (to preserve the previous layout). Then you can save it again. In general, we do not have a mechanism that allows using the same layout file with different versions of the program and this should be handled manually. 

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Victor
Top achievements
Rank 2
answered on 18 Apr 2017, 07:25 PM

Hi Dimitar, this indeed helps a lot.

I am going to give it a try.

Kind regards 

Victor

0
Victor
Top achievements
Rank 2
answered on 18 Apr 2017, 07:49 PM

Hello Dimitar,

Another question : If I load the just saved xml, the colums still go back in their previous position with their previous width.

Isn't it possible just to load the conditional formats?

KG

Vic

0
Dimitar
Telerik team
answered on 19 Apr 2017, 09:28 AM
Hi Victor,

Since each column has a property that contains all ConditionalFormattingObjects there is no way to save only these objects. They do not keep a reference to the column.

Should you have any other questions do not hesitate to ask. 

Regards,
Dimitar
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
technicast
Top achievements
Rank 1
answered on 26 Mar 2018, 09:46 PM

Your list is good at gathering all the individual Conditional formatting objects. 

Is there one statement that includes all the objects associated with conditional formatting?  I know there is a type "ConditionalFormattingObjectCollection".  

0
Dimitar
Telerik team
answered on 27 Mar 2018, 08:17 AM
Hello Eric,

The objects are stored for each column (each column has a ConditionalFormattingObjectList property which type is ConditionalFormattingObjectCollection). There is no other place where all conditional formatting objects are stored.

Could you please share what is your goal for this case. Maybe we can suggest a solution.

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
technicast
Top achievements
Rank 1
answered on 27 Mar 2018, 02:04 PM

My goal is to streamline the code. Adding the individual items would seem to be more error prone.  Misspelling, miss-naming etc.  Your list was was very enlightening to me.  I have seen other posts where it states the CF cannot be serialized and you have to write your own serializer.

I guess I don't understand how things work exactly. Why do you add the list then follow it with the individual items in the list?

radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(GridViewDataColumn),"ConditionalFormattingObjectList", newDesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Content));

radGridView1.XmlSerializationInfo.SerializationMetadata.Add(typeof(ConditionalFormattingObject), "Name", DesignerSerializationVisibilityAttribute.Visible);

<...>

Why is not just adding the list enough?  (Of course, I tried it and it didn't pick up the items)

 

 

0
Dimitar
Telerik team
answered on 28 Mar 2018, 10:51 AM
Hello Eric,

This is how the serialization works, you need to add each property to build the serialization hierarchy. There is no way to simplify this code. 

Please note that the condition formatting is serialized by default and you do not need explicitly to set this to save it. This is a specific case when we only want to save specific properties. 

Should you have any other questions do not hesitate to ask.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Victor
Top achievements
Rank 2
Hristo
Telerik team
technicast
Top achievements
Rank 1
Share this question
or