0

I am currently making a MS Project 2016 Add-In and I need to color specific task ( row of the task ), when a condition is true. I am using c# .NET4

I made a method:

public void colorYellow(MSProject.Task task){
        Globals.ThisAddIn.Application.SelectRow(task.ID);
        Globals.ThisAddIn.Application.ActiveCell.CellColor = PjColor.pjYellow;      
    }

I am getting exception: Unexpected method error.

Is there a way how to color whole task row somehow? Thanks for your answer!

  • With line 1 being the function prototype, on what line does the error occur if you step through with the debugger? It should be possible to do what you want: hang in there. – Jerred S. Jul 13 '18 at 12:59

1 Answers1

0

The Unexpected method error comes from the fact that you are actually selecting a blank row because the SelectRow method is relative by default. Unless the optional, second argument RowRelative is passed in as False, the selection moves task.ID rows forward. So try:

Globals.ThisAddIn.Application.SelectRow(task.ID, false);

See MSDN reference for the SelectRow method

If the cell color is still not changing, look at the Font32Ex method for an alternative way to change the cell color. Despite the MSDN reference indicating the Color argument changes the font color, several SO posts (and my own testing) show that it actually changes the background color. (Note: this is far from the only case where the MSDN reference page for MS Project is not accurate.)

SO post #1 about changing background color

SO post #2 about color coding

(Note on code sample: I am a vb.net programmer... not sure if that's the correct syntax for passing False as the second argument.)

Rachel Hettinger
  • 7,927
  • 2
  • 21
  • 31