Search code examples
c#com-interopms-projectoffice-automation

Hide a column in MS-Project with C# Interop


I'm doing a WinForm program on Visual Studio who automates the creation and automation of a MS-Project file.

I use those references :

Microsoft Office 16.0 Object Library
Microsoft Office Project 16.0 Object Library
Microsoft Project Task Launch Control

In some point in my MS-Project file, I want to customize displaying of the columns in the table.

For this purpose I use TableEditEx function. I've already made a new customized column like this :

Microsoft.Office.Interop.MSProject.Application projApp = new Microsoft.Office.Interop.MSProject.Application();
projApp.Application.SelectTaskColumn(Column: "Add New Column");
projApp.Application.TableEditEx(Name: "&Entry", TaskTable: true, NewName: "Progression", NewFieldName: "Text1", Title: "Completion", ShowInMenu: true, Width: 12);
projApp.Application.TableApply(Name: "&Entry");

And now I want to hide column "Resource Names" for example. To do so I tried the following code :

projApp.Application.SelectTaskColumn(Column: "Resource Names");
projApp.Application.TableEditEx(Name: "&Entry", TaskTable: true, Create: false, ShowInMenu: false);
projApp.Application.TableApply(Name: "&Entry");

But it doesn't appear to do anything more than selecting the column.

I've researched here :

Documentation : TableEditEx


Solution

  • To hide the column (not delete it), set the column width = 0:

    projApp.Application.TableEditEx(Name: "&Entry", TaskTable: true, FieldName: "Resource Names", Width: 0);
    projApp.Application.TableApply(Name: "&Entry");
    

    That way, the user can unhide the column later without having to edit the table to insert it.