大多数人习惯于使用舒适的排序选项,例如在Windows资源管理器中:单击列的表头将按升序或降序对文件进行排序,这由表中向上或向下指示的箭头指示头。
我们想要实现的目标
下图显示了Windows资源管理器中按“升级修改日期”列按升序排序的文件,该文件由向上指向的小箭头指示:

这个小箭头可以很容易地添加到您的甘特图 – 只需按照下面描述的三个步骤。
第一步:创建箭头
您需要两个用于显示箭头的图形文件,以下称为arrow-down.png和arrow-up.png, 它们必须作为资源 添加到Visual Studio解决方案中。

第二步:自定义表格格式
在XGantt表格式StandardListCaption中,您必须勾选所有字段的文本/图形组合复选框。

第三步:添加代码
执行上述步骤后,您只需向Gantt控件添加一些代码行:
int _sortedByColumn = 3;private void Form1_Load(object sender, EventArgs e){ //Make the resources available for XGantt: //In the following 2 lines the namespace has be be adjusted as necessary. vcGantt1.SetImageResource("*ArrowDown",Default_Configuration.Properties.Resources.arrow_down); vcGantt1.SetImageResource("*ArrowUp", Default_Configuration.Properties.Resources.arrow_up); //Set the arrow in the table column by which your nodes are initially sorted: VcTable activeTable = vcGantt1.TableCollection.Active; VcTableFormat standardListCaptionTF = activeTable.TableFormatCollection.FormatByName("StandardListCaption"); //Select the table format field by which your nodes are initially sorted: VcTableFormatField tff = standardListCaptionTF.get_FormatField(2); tff.GraphicsFileName = "*ArrowUp"; //...} private void vcGantt1_VcTableCaptionLeftClicking(object sender, VcTableClickingEventArgs e){ VcNodeLevelLayout nodeLevelLayout = vcGantt1.NodeLevelLayout; VcTableFormat standardListCaptionTF = e.Table.TableFormatCollection.FormatByName("StandardListCaption"); VcTableFormatField tff = standardListCaptionTF.get_FormatField((short)(e.ColumnNumber - 1)); if (e.ColumnNumber == _sortedByColumn) //Clicked again on the same column: Just reverse the sort order! { if (nodeLevelLayout.get_SortOrder(0) == VcNodeSortingOrder.vcAscending) { nodeLevelLayout.set_SortOrder(0, VcNodeSortingOrder.vcDescending); tff.GraphicsFileName = "*ArrowDown"; } else { nodeLevelLayout.set_SortOrder(0, VcNodeSortingOrder.vcAscending); tff.GraphicsFileName = "*ArrowUp"; } } else //Clicked on another column: Sort by this column. Sort order: ascending { nodeLevelLayout.set_SortDataFieldIndex(0, tff.Index); nodeLevelLayout.set_SortOrder(0, VcNodeSortingOrder.vcAscending); tff.GraphicsFileName = "*ArrowUp"; tff = standardListCaptionTF.get_FormatField((short)(_sortedByColumn - 1)); tff.GraphicsFileName = string.Empty; } vcGantt1.SortNodes(); _sortedByColumn = e.ColumnNumber;}
结果
如果一切都按计划进行,甘特图中的表格标题现在应该显示排序箭头,如下图所示:


下一步
现在您可以去试试看了。如果到目前为止您还没有使用VARCHART XGantt,欢迎随时下载最新试用版。
VARCHART XGantt最新版免费下载试用
标签:甘特图甘特图开发资源优化资源管理
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!