Loktis
Loktis

Reputation: 72

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

Upvotes: 0

Views: 1121

Answers (2)

Rachel Hettinger
Rachel Hettinger

Reputation: 8442

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.

Upvotes: 2

Loktis
Loktis

Reputation: 72

Okay,

I found a solution on my own. I've tried doing a macro to get the VBA code to hide a column and I got this :

SelectTaskColumn Column:="Resource Names"
ColumnDelete

And I converted it in C# code :

projApp.Application.SelectTaskColumn(Column: "Resource Names");
projApp.Application.ColumnDelete();

And it worked, thanks myself !

Upvotes: 1

Related Questions