翻譯|使用教程|編輯:黃竹雯|2018-10-25 17:03:22.000|閱讀 417 次
概述:本文將告訴您使用VARCHART XGantt時,為分組甘特圖添加舒適排序選項的三個步驟。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
大多數人習慣于使用舒適的排序選項,例如在Windows資源管理器中:單擊列的表頭將按升序或降序對文件進行排序,這由表中向上或向下指示的箭頭指示頭。
如果您也可以在VARCHART XGantt中使用此功能,那不是很好嗎?在本文中,我將向您展示如何通過三個簡單的步驟完成這項工作,并且只需很少的一部分編程。
下圖顯示了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,歡迎隨時下載最新試用版。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn