原創(chuàng)|使用教程|編輯:郝浩|2013-03-27 16:53:31.000|閱讀 1473 次
概述:甘特圖開發(fā)中的活動和鏈接要顯示的話,VARCHART XGantt需要為甘特圖提供數(shù)據(jù)支撐。本文將詳細(xì)介紹操作方法。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
甘特圖開發(fā)中的活動和鏈接要顯示的話,VARCHART XGantt需要為甘特圖提供數(shù)據(jù)支撐。默認(rèn)情況下,相關(guān)的通信會用到兩個表:
在窗體中放入VARCHART XGantt時,一些基本字段已經(jīng)預(yù)先定義了。《如何將XGantt置入到VS窗體中》
Maindata數(shù)據(jù)表中的字段:

Relations數(shù)據(jù)表中的字段:

其他更多的字段就需要我們自己手動定義了。你可以在設(shè)計時通過對話框管理數(shù)據(jù)表(下半部分)或者在運行時使用VcDataTableFieldCollection對象的Add(...)方法添加。
如果你覺得默認(rèn)的表不夠多,你可以自己創(chuàng)建一些,在擴(kuò)展屬性頁找到常規(guī)選項,點擊啟用Extended data tables,然后在Administrate Data Tables的下半部分進(jìn)行設(shè)置。

VcDataRecordCollection的DataRecordByID()方法允許通過主鍵快速查找對象。
為了使示例中的活動和鏈接可見,你需要在數(shù)據(jù)表中存入一些數(shù)據(jù)。
你可以使用VcData-RecordCollection對象的Add(...)方法。EndLoading方法則為相應(yīng)的圖表數(shù)據(jù)組成數(shù)據(jù)。請在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;
字段的順序與數(shù)據(jù)定義中的字段順序相對應(yīng)。新記錄必須明確說明哪一個不能為空。在記錄中的日期對應(yīng)數(shù)據(jù)定義表中的DateFormat定義。解釋的持續(xù)時間取決于時間單位的設(shè)置。預(yù)先設(shè)定的以天為單位,你可以在常規(guī)屬性頁的設(shè)置里面進(jìn)行修改。
日期輸出的格式與常規(guī)屬性頁上的表和每個對話框定義的保持一致。

除了上面介紹的添加數(shù)據(jù)的方法外,你也可以從一個CSV文件中加載數(shù)據(jù)。對應(yīng)的文件結(jié)構(gòu)如下:
示例代碼
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;
每個記錄都有它自己的行。每行內(nèi)容對應(yīng)的參數(shù)通過VcDataRecordCollection對象類型的Add(...) 方法傳遞。
Maindata數(shù)據(jù)表的記錄被列在第一位,其次是關(guān)系數(shù)據(jù)表的記錄。使用****表的名稱****標(biāo)志著一個記錄組。
如果你保存這種類型的文件例如intro.csv,你可以導(dǎo)入的數(shù)據(jù)如下:
Example Code VB.NET
VcGantt1.Open("c:\intro.csv")
Example Code C#
vcGantt1.Open(@"c:\intro.csv");
到現(xiàn)在為止,你還沒有看到任何活動,因為時間刻度還沒有調(diào)整為同期。時間刻度顯示的范圍可以通過TimeScaleStart和TimeScaleEnd屬性定義,或VcGantt對象的OptimizeTimeScaleStartEnd(...)方法從數(shù)據(jù)中確定。
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;
}
如果你現(xiàn)在運行程序,將會看到下圖中的結(jié)果:

本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@ke049m.cn
文章轉(zhuǎn)載自:慧都控件網(wǎng)