Can someone show me some working examples of how to programmatically hide a column? I see the gantt.ExecuteCommand(GanttCommandId.HideColumn, object) method, but the api documentation is weak. What kind of object am I supposed to pass to the second parameter? I have tried strings (with the key name of the column), instances of ProjectColumnDefinitions ... etc with no luck.
Does anyone know how to do this? I would think this would be fairly simple to do...
Thanks in advance,
Tim
Hello Tim,
I am just checking if you require any further assistance on the matter.
GanttGridColumn is just a structure that identifies a column via a key so it is ok to construct a new one and pass that as the parameter for the HideColumn command. Typically the visible columns are maintained via the ProjectTable which is coming from the ViewProvider. I'm assuming you're letting the control use the default ProjectViewProviderBase which will construct several ProjectTables matching what MS Project has - so an Entry table, Constraint Dates table, and Schedule table. It prepopulates these with ProjectColumn instances which provides actual information about the column such as the key, width, header, etc. So if you're using this default provider and you want to see what columns are displayed you can get the Table from the xamGantt. If you want to hide one then you could either remove the column from the table's columns collection or use the HideColumn and just construct a GanttGridColumn with the Key of that column. The latter approach would allow the gantt to raise the ColumnVisibilityChanging/ed events. If you remove the column directly from the table's columns then that won't happen.
If you want to actually define what columns and tables should be available then you might use the ListBackedProjectViewProvider or you could just get the ViewProviderResolved from the xamGantt and manipulate its Tables, etc. Another option would be to derive a class from ProjectViewProviderBase and just populate the Tables and Views collection in the ctor - that is basically the default internally provided view provider does.
Your example doesn't work, for example creating a new GanttGridColumn("Id") won't remove the "Id" column from the grid.
If I select the column from the user Interface first, and then pass in the selected column the GanttCommandId.HideColumn does work, for example, this will work:
IList<GanttGridColumn> selCols = gantt.SelectedColumns;
GanttGridColumn col = selCols[0];
gantt.ExecuteCommand(GanttCommandId.HideColumn, col);
I don't see anyway to return a list of all of the available columns from the XamGantt class, if a method like that existed, I could use the list to remove the "Id" column.
Your example appears to create a new instance of a column (that isn't actually in the existing grid), so the GanttCommand.HideColumn doesn't remove the existing "Id" column from the grid.
I am trying to have my Grid only show the Name, Start and Finish columns on the user interface after it is initialized, what is the best way to do this? I was thinking I would hide the columns I don't want to show, but perhaps there is another (better) way to do this? I see the ColumnSettings Structure, perhaps you could give me an example of how to just display the three columns I mentioned above?
Hello Timothy,
I have been looking into your post and you need to pass a GanttGridColumn object as second parameter like e.g. :
this.xamGantt.ExecuteCommand(GanttCommandId.HideColumn, new GanttGridColumn("ColumnKey"));
Please let me know, if you need any further assistance on this matter.