12 Answers, 1 is accepted
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
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
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
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
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
Hi Dimitar, this indeed helps a lot.
I am going to give it a try.
Kind regards
Victor
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
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
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".
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
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)
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