If you use a GanttChartDataGrid component and you use objects inheriting from the default GanttChartItem class to provide CustomField properties of your own (possibly showing them as well into the grid’s Columns) you may want to export/import the custom field values to/from Project XML formatted strings/files as well.
In this case you will need to use a ProjectXmlSerializer instance (instead of SaveProjectXml method of the component) and set up event handlers for GanttChartItemSaving (for serialization) and GanttChartItemLoading events (for deserialization) and inject custom logic to save/load custom values to/from the Project XML elements yourself.
For example (assuming CustomTaskItem inherits from GanttChartItem and defines a CustomField property of type string):
// Save to file/Get XML string:
var serializer = new GanttChartDataGrid.ProjectXmlSerializer(GanttChartDataGrid);
serializer.GanttChartItemSaving += Serializer_GanttChartItemSaving;
var xml = serializer.GetXml();
… // use xml
private void Serializer_GanttChartItemSaving(object sender, GanttChartView.ProjectXmlSerializer.GanttChartItemSavingEventArgs e)
{
var customItem = e.GanttChartItem as CustomTaskItem;
var xml = e.OutputXml;
var element = XElement.Parse(xml);
element.Add(new XElement(XName.Get("CustomField", "custns"), customItem.CustomField));
xml = element.ToString();
e.OutputXml = xml;
}
// Load from string/file: var xml = …; //prepare XML string var serializer = new GanttChartDataGrid.ProjectXmlSerializer(GanttChart); serializer.GanttChartItemLoading += Serializer_GanttChartItemLoading; serializer.Load(xml); private void Serializer_GanttChartItemLoading(object sender, GanttChartView.ProjectXmlSerializer.GanttChartItemLoadingEventArgs e) { var item = e.GanttChartItem; var element = e.SourceElement; var customItem = new CustomTaskItem { Content = item.Content, Start = item.Start, … CustomField = element.Element(XName.Get("CustomField", "custns"))?.Value }; e.GanttChartItem = customItem; }