Bar style not consistently used in mpp

Hi,

I’m having trouble implementing bar styles. Although, I’m setting bar styles for every task in the project, only some of the tasks are showing the assigned style. When I read my edited mpp file using Aspose, I can see a bar style is assigned to each task. But when I open this file in Project 2010 or 2016 only some tasks show the defined style.

I find some of the documentation confusing. For example, the GanttbarStyle Property ShowFor is defined as “Task categories separated by semicolumns, which are to be represented by the gantt bar.” What is a “semicolumns?” Is this a typo, should it be “semicolon?” Also, I can’t find a definition of “Task categories”. In examples, this seems to be the Uid. Is this correct? When I use a string containing semicolons between Uid’s for the ShowFor property, the bar style is not applied.

Also, what is the GanttbarStyle Property Row? Why can it be only 1 to 4?

The fact that some of the tasks show my assigned bar style suggests to me that the functionally works but I’m implementing this feature or something else in the project incorrectly.

The following is my method for setting the bar style. The bar style for each Task is recorded as XML in a SQL table called MMPFormat and is identified by field called UID.

Any thoughts or suggestions would be appreciated.

Thanks!

private void AddBarstyleToProject()
{
    ChildTasksCollector collector = new ChildTasksCollector();
    TaskUtils.Apply(_project.RootTask, collector, 0);
    foreach (Aspose.Tasks.Task tsk in collector.Tasks)
    {
        string sqlBarStyle = string.Format("SELECT top 1 [BarStyle] FROM [QmV3].[QmSchema].[ MMPFormat] where UID = {0}", tsk.Get(Tsk.Uid));
        var barStyle = _UOW.ExecuteScalar(sqlBarStyle);
        if (barStyle != null)
        {
            GanttBarStyle style = new GanttBarStyle();
            GanttBarStyleExport taskBarStyle = Serializer.XmlDeserializeFromString<GanttBarStyleExport>(barStyle.ToString());
            style.Row = taskBarStyle.Row;
            style.From = taskBarStyle.From;
            style.To = taskBarStyle.To;
            style.LeftField = taskBarStyle.LeftField;
            style.RightField = taskBarStyle.RightField;
            style.TopField = taskBarStyle.TopField;
            style.BottomField = taskBarStyle.BottomField;
            style.InsideField = taskBarStyle.InsideField;
            style.StartShape = taskBarStyle.StartShape;
            style.StartShapeColor = ColorTranslator.FromHtml(taskBarStyle.StartShapeColorHex);
            style.StartShapeType = taskBarStyle.StartShapeType;
            style.EndShape = taskBarStyle.EndShape;
            style.EndShapeColor = ColorTranslator.FromHtml(taskBarStyle.EndShapeColorHex);
            style.EndShapeType = taskBarStyle.EndShapeType;
            style.MiddleShape = taskBarStyle.MiddleShape;
            style.MiddleShapeColor = ColorTranslator.FromHtml(taskBarStyle.MiddleShapeColorHex);
            style.MiddleFillPattern = taskBarStyle.MiddleFillPattern;
            style.ShowFor = tsk.Get(Tsk.Uid).ToString();
            GanttChartView view = _project.DefaultView as GanttChartView;
            view.CustomBarStyles.Add(style);
        }
    }
}
I appreciate your assistance. Your comments and thoughts greatly improved my understanding of the problem.

I used your code to set the bar style but I still had the same problem. However, if after updating and saving the mpp file with Aspose, I copied and paste all the tasks into a new blank Project 2016 file and then ran your code. The application of bar styles suddenly showed correctly in Project.

I don’t know exactly what’s going on, but I know how to solve it. The unique identifiers for the project tasks must be in a simple sequence. Mine weren’t; they were out of order with numbers missing. By examining the mpp updated by Aspose, it appears that Aspose is correctly associating bar styles with a task Uids but it seems that Project has a problem applying these associations.

This issue can now be considered solved.

Thank you!

Hi,


Thank you for sharing your feedback and please feel free to write to us in case of any further inquiry.