原創|使用教程|編輯:郝浩|2013-03-27 16:53:31.000|閱讀 1454 次
概述:甘特圖開發中的活動和鏈接要顯示的話,VARCHART XGantt需要為甘特圖提供數據支撐。本文將詳細介紹操作方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
甘特圖開發中的活動和鏈接要顯示的話,VARCHART XGantt需要為甘特圖提供數據支撐。默認情況下,相關的通信會用到兩個表:
在窗體中放入VARCHART XGantt時,一些基本字段已經預先定義了。《如何將XGantt置入到VS窗體中》
Maindata數據表中的字段:
Relations數據表中的字段:
其他更多的字段就需要我們自己手動定義了。你可以在設計時通過對話框管理數據表(下半部分)或者在運行時使用VcDataTableFieldCollection對象的Add(...)方法添加。
如果你覺得默認的表不夠多,你可以自己創建一些,在擴展屬性頁找到常規選項,點擊啟用Extended data tables,然后在Administrate Data Tables的下半部分進行設置。
VcDataRecordCollection的DataRecordByID()方法允許通過主鍵快速查找對象。
為了使示例中的活動和鏈接可見,你需要在數據表中存入一些數據。
你可以使用VcData-RecordCollection對象的Add(...)方法。EndLoading方法則為相應的圖表數據組成數據。請在Load事件中輸入如下代碼:
Example Code VB.NET
Dim dataTable As VcDataTable Dim dataRecCltn As VcDataRecordCollection VcGantt1.ExtendedDataTablesEnabled = True dataTable = VcGantt1.DataTableCollection.DataTableByName("Maindata") dataRecCltn = dataTable.DataRecordCollection dataRecCltn.Add("1;Node 1;07.05.2010;;5") dataRecCltn.Add("2;Node 2;14.05.2010;;5") dataRecCltn.Add("3;Node 3;21.05.2010;;5") dataTable = VcGantt1.DataTableCollection.DataTableByName("Relations") dataRecCltn = dataTable.DataRecordCollection dataRecCltn.Add("1;1;2") dataRecCltn.Add("2;2;3") VcGantt1.EndLoading
Example Code C#
vcGantt1.ExtendedDataTablesEnabled = true; VcDataTable dataTable = vcGantt1.DataTableCollection.DataTableByName("Maindata"); VcDataRecordCollection dataRecCltn = dataTable.DataRecordCollection; dataRecCltn.Add("1;Node 1;07.05.2010;;5"); dataRecCltn.Add("2;Node 2;14.05.2010;;5"); dataRecCltn.Add("3;Node 3;21.05.2010;;5"); dataTable = vcGantt1.DataTableCollection.DataTableByName("Relations"); dataRecCltn = dataTable.DataRecordCollection; dataRecCltn.Add("1;1;2"); dataRecCltn.Add("2;2;3"); vcGantt1.EndLoading;
字段的順序與數據定義中的字段順序相對應。新記錄必須明確說明哪一個不能為空。在記錄中的日期對應數據定義表中的DateFormat定義。解釋的持續時間取決于時間單位的設置。預先設定的以天為單位,你可以在常規屬性頁的設置里面進行修改。
日期輸出的格式與常規屬性頁上的表和每個對話框定義的保持一致。
除了上面介紹的添加數據的方法外,你也可以從一個CSV文件中加載數據。對應的文件結構如下:
示例代碼
1;Node 1;07.05.2010;;5; 2;Node 2;14.05.2010;;5; 3;Node 3;21.05.2010;;5; **** 1;1;2; 2;2;3;
每個記錄都有它自己的行。每行內容對應的參數通過VcDataRecordCollection對象類型的Add(...) 方法傳遞。
Maindata數據表的記錄被列在第一位,其次是關系數據表的記錄。使用****表的名稱****標志著一個記錄組。
如果你保存這種類型的文件例如intro.csv,你可以導入的數據如下:
Example Code VB.NET
VcGantt1.Open("c:\intro.csv")
Example Code C#
vcGantt1.Open(@"c:\intro.csv");
到現在為止,你還沒有看到任何活動,因為時間刻度還沒有調整為同期。時間刻度顯示的范圍可以通過TimeScaleStart和TimeScaleEnd屬性定義,或VcGantt對象的OptimizeTimeScaleStartEnd(...)方法從數據中確定。
Example Code VB.NET
VcGantt1.TimeScaleEnd = New DateTime(2011, 1, 1) VcGantt1.TimeScaleStart = New DateTime(2010, 5, 4)
Example Code C#
vcGantt1.TimeScaleEnd = new DateTime(2011,1,1); vcGantt1.TimeScaleStart =new DateTime(2010,5,4);
下面的代碼你可能會用到:
Example Code VB.NET
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load VcGantt1.Width = ClientSize.Width - VcGantt1.Left VcGantt1.Height = ClientSize.Height - VcGantt1.Top Dim dataTable As VcDataTable Dim dataRecCltn As VcDataRecordCollection vcGantt1.ExtendedDataTablesEnabled = True dataTable = VcGantt1.DataTableCollection.DataTableByName("Maindata") dataRecCltn = dataTable.DataRecordCollection dataRecCltn.Add("1;Node 1;03.05.2010;;5") dataRecCltn.Add("2;Node 2;08.05.2010;;5") dataRecCltn.Add("3;Node 3;15.05.2010;;5") dataTable = VcGantt1.DataTableCollection.DataTableByName("Relations") dataRecCltn = dataTable.DataRecordCollection dataRecCltn.Add("1;1;2") dataRecCltn.Add("2;2;3") VcGantt1.EndLoading() VcGantt1.OptimizeTimeScaleStartEnd(3) End Sub Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize VcGantt1.Width = ClientSize.Width - VcGantt1.Left VcGantt1.Height = ClientSize.Height - VcGantt1.Top End Sub
Example Code C#
private void Form1_Load(object sender, System.EventArgs e) { vcGantt1.Width = ClientSize.Width - vcGantt1.Left; vcGantt1.Height = ClientSize.Height - vcGantt1.Top; vcGantt1.ExtendedDataTablesEnabled = true; VcDataTable dataTable = vcGantt1.DataTableCollection.DataTableByName("Maindata"); VcDataRecordCollection dataRecCltn = dataTable.DataRecordCollection; dataRecCltn.Add("1;Node 1;03.05.2010;;5"); dataRecCltn.Add("2;Node 2;08.05.2010;;5"); dataRecCltn.Add("3;Node 3;15.05.2010;;5"); dataTable = vcGantt1.DataTableCollection.DataTableByName("Relations"); dataRecCltn = dataTable.DataRecordCollection; dataRecCltn.Add("1;1;2"); dataRecCltn.Add("2;2;3"); vcGantt1.EndLoading(); vcGantt1.OptimizeTimeScaleStartEnd(3); } private void Form1_Resize(object sender, System.EventArgs e) { vcGantt1.Width = ClientSize.Width - vcGantt1.Left; vcGantt1.Height = ClientSize.Height - vcGantt1.Top; }
如果你現在運行程序,將會看到下圖中的結果:
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網