当前位置:网站首页>Getting started with varhart xgantt
Getting started with varhart xgantt
2020-11-06 22:27:00 【roffey】
Gantt Chart (Xgantt) from 1998 The first commercial version of the year was devoted to the research and development of control for planning and project management , after 20 Years of accumulation and precipitation , At present, it can provide software developers and end users with top-level planning and project management control products , Help users quickly integrate the Gantt chart needed by project management software , Network diagram , Resource histogram , Calendar , Resource scheduling and other functional modules , And provide a full range of support and services .
VARCHART XGantt Is a powerful Gantt chart control , Its modular design allows you to create applications that meet your needs .XGantt Can be used for .NET,ActiveX and ASP.NET Applications , Can quickly 、 Simply integrate into your application , Help you identify performance bottlenecks 、 Avoid delays and efficient use of resources , Make complex data easier to understand .
Example : Tutorial project 1
Development environment as a code example , We use up Visual Studio .NET 2010. Our first sample will show the following results :

Our sample collection includes sample tutorial projects 1, This sample project demonstrates VARCHART XGantt Built in interaction of , And make it easy for you to understand the steps described in our blog series .
Now? , Let's go !
Place the Gantt chart control on the form
Yes Visual Studio 2010 User reminders : As we're at the introductory blog #1 As already mentioned in , Before you drag the Gantt chart control to the form , Remember to change the target framework from .NET Framework Client Profile Change to .NET Framework 4 . Set up (C#) or Advanced compiler settings (VB), Because the former lacks System.Design.dll, This is required for design time property pages . If you don't change the frame , An error message will pop up when you try to drag the control onto the form .
To put VARCHART XGantt Control placed on the form , please xgantt_icon_toolbox Select its icon in the toolbox , And draw a frame in the form where you want it to appear .
If you want to run VARCHART Windows Forms The bottom and right sides of the control are adjusted to the full size of the window , Please use the control's anchor or dock attribute .
Tips :
Use data types and “ enumeration ” Element time , At the beginning of the program “ The name space ” Instructions will save you detailed reference instructions .
VB: Imports NETRONIC.XGantt
C#: using NETRONIC.XGantt;
VcNodeCollection instead of NETRONIC.XGantt.VcNodeCollection.
Provide data
To show activities and links ,VARCHART XGantt Data needs to be provided . By default , Two tables are used for the necessary communication :
- NodeTable( Also known as Maindata)
- LinkTable( Also known as “ Relationship ”)
Put... In the form VARCHART XGantt when , The basic fields have been set .
Maindata Data table fields :

Fields in relational tables
The other fields needed need to be defined manually . You can use the dialog box at design time “ Management data sheet ”( Lower part ) To perform this operation , Or through objects at run time VcDataTableFieldCollection Of Add(...) Method to do this .
If you need more tables than are defined by default , You can click after enabled extended data table on property page general , stay “ Management data sheet ” Create them at the top of the dialog .

The method DataRecordByID() Of VcDataRecordCollection Allows you to quickly find objects through primary keys .
To make activities and links visible in our introductory example , You need to first enter some records in the data table .
This can be done by using this method to add (...) Object type VcDataRecordCollection. The method EndLoading Complete the data input on the corresponding chart . So , Please put it on the form Load Event, enter the following line of code .
Sample code C#
vcGantt1.ExtendedDataTablesEnabled = true;
VcDataTable dataTable = vcGantt1.DataTableCollection.DataTableByName("Maindata");
VcDataRecordCollection dataRecCltn = dataTable.DataRecordCollection;
dataRecCltn.Add(“ 1; node 1; 04.05.2015 ;; 5 ;; Group 1; Group A;”);
dataRecCltn.Add(“ 2; Node 2; 11.05.2015 ;; 5 ;; Group 1; Group A;”);
dataRecCltn.Add(“ 3; node 3; 18.05.2015 ;; 5 ;; Group 1; Group B;”);
dataTable = vcGantt1.DataTableCollection.DataTableByName(“ Relations”);
dataRecCltn = dataTable.DataRecordCollection;
dataRecCltn.Add("1;1;2");
dataRecCltn.Add("2;2;3");
vcGantt1.EndLoading();
Values in records are separated by semicolons . The order of the fields must correspond to the order of the fields in the data definition . The new record must not have an empty ID . The date in the record must be the same as that in the data definition table DateFormat The definition corresponds to . The interpretation of the duration depends on the setting of the time unit . It is preset to days, You can go to “ routine ” Modify it on the properties page .
For the table and “ routine ” Each dialog box on the property page defines the “ date ” Output format .

from CSV File load data
perhaps , You can also choose from CSV File load data . The structure of the file must correspond to the following scheme :
**** Maindata ****
1;Node 1;04.05.2015;;5;;Group 1;Group A;
2;Node 2;11.05.2015;;5;;Group 1;Group A;
3;Node 3;18.05.2015;;5;;Group 1;Group B;
**** Relations ****
1;1;2;
2;2;3;
Each record has its own line . The content and object type of these lines VcDataRecordCollection Methods Add(...) The parameters passed correspond to .
First, list Maindata Records of data sheets , And then there was Relations Records of data sheets . Use **** Table name **** Mark the beginning of the record group .
If you use the name intro.csv For example, this kind of file is saved , You can import data as follows :
Sample code C#
vcGantt1.Load(@"c:\intro.csv");
Specify the period of time represented
Up to now , You won't see any activities , Because the time scale has not been adjusted to the corresponding time period . The display range of the timescale can be displayed through the properties TimeScaleStart and TimeScaleEnd Definition , You can also go through objects VcGantt Of OptimizeTimeScaleStartEnd(...) Method from the data to determine .
Sample code C#
private void Form1_Load(object sender, System.EventArgs e)
{
vcGantt1.ExtendedDataTablesEnabled = true;
VcDataTable dataTable = vcGantt1.DataTableCollection.DataTableByName("Maindata");
VcDataRecordCollection dataRecCltn = dataTable.DataRecordCollection;
dataRecCltn.Add(“ 1; node 1; 04.05.2015 ;; 5 ;; Group 1; Group A;” );
dataRecCltn.Add(“ 2; node 2; 11.05.2015 ;; 5 ;; Group 1; Group A;” );
dataRecCltn.Add(“ 3; node 3; 18.05.2015 ;; 5 ;; Group 1; Group B;” );
dataTable = vcGantt1.DataTableCollection.DataTableByName("Relations");
dataRecCltn = dataTable.DataRecordCollection;
dataRecCltn.Add("1;1;2");
dataRecCltn.Add("2;2;3");
vcGantt1.EndLoading();
vcGantt1.OptimizeTimeScaleStartEnd(3);
}
If you run the program now , The result should be as shown in the figure below .

Calculate the end date
The table column containing the end date is still empty . have access to VARCHART XGantt Contains a calendar from “ Start ” and “ The duration of the ” Field to calculate the end time of the activity .
In the default calendar , Working day ( Monday to Friday ) Pre defined as activity time , It's going to be the weekend ( Saturday and Sunday ) Defined as inactive time .
You can identify the inactive time in the graph by the gray background . By disabling “ node ” On the properties page “ Nodes use calendars ” Options , You can close the calendar .
Please note the difference in calculation between using and not using the calendar :
If you activate the calendar , It starts on Friday and continues 3 The day will end on Tuesday . No calendar , The event will end on Sunday .
You can use objects VcCalendar Of AddDuration(...) Method to calculate the end date . This requires the start and duration of each activity . These fields can be accessed through their index . After the end date set by this method set_DataField(...), The method updates () Of VcNode You need to call the changes to be displayed .
Sample code C#
foreach (VcNode node in vcGantt1.NodeCollection)
{
VcCalendar tmpCal = vcGantt1.CalendarCollection.Active;
DateTime tmpDate = tmpCal.AddDuration((DateTime)node.get_DataField(2),
Convert.ToInt32(node.get_DataField(4)));
node.set_DataField(3, tmpDate);
node.Update();
}
The start and end dates of activities created or modified by mouse interaction are automatically placed at the activity time .

contrary , Can be API Or set the date set by the edit dialog box to non working time .

The date generated by calculation is always placed in working hours . To make sure that you will API Set the date into the working time , You need to calculate the start date from the end date and activity duration .
Sample code C#
tmpDate = tmpCal.AddDuration((DateTime)node.get_DataField(3), (-1) * Convert.ToInt32(node.get_DataField(4))); node.set_DataField(2, tmpDate);
To keep the data consistent , The missing duration or missing duration should be considered incorrect , And reset it to 0. If the start date is missing , The end date cannot be calculated . The code is called SetNodeEndDate(...) In a separate method .
Sample code C#
private void SetNodeEndDate(VcNode node)
{
// Avoid empty duration or negative duration
if ((string) node.get_DataField(4) == "" ||
Convert.ToInt32(node.get_DataField(4)) < 0) node.set_DataField(4,"0"); // If the start date is empty then the end date should also be empty if (node.get_DataField(2).ToString() == "31.12.1899 00:00:00") node.set_DataField(3,""); else { // "Assign calendar to nodes" on the Nodes property page has to be checked VcCalendar tmpCal = vcGantt1.CalendarCollection.Active; DateTime tmpDate = tmpCal.AddDuration( (DateTime)node.get_DataField(2), Convert.ToInt32(node.get_DataField(4))); node.set_DataField(3, tmpDate); // start date only in active timespans tmpDate = tmpCal.AddDuration((DateTime)node.get_DataField(3), (-1) * Convert.ToInt32(node.get_DataField(4))); node.set_DataField(2, tmpDate); node.Update(); }
The calculation of the date is necessary :
- After the activity is loaded
- After modifying the date or duration through the data edit dialog box or in place editor
- adopt API After modifying the activity value
however , After modification through mouse interaction , There is no need to start the calculation , Because in this case , Internal calculations will be performed automatically .
A computes the loop , It includes all nodes that can be set by attributes NodeCollection in question VcGantt object . Its code will be added to the event Form1_Load(...) At the end of .
Sample code C#
// Calculate end date for all nodes
foreach (VcNode node in vcGantt1.NodeCollection)
SetNodeEndDate(node);
Data changes caused by users can be made through events VcNodeModifiedEx obtain . The added method call will calculate the end date .
Sample code C#
private void vcGantt1_VcNodeModifiedEx(object sender, VcNodeModifiedExEventArgs e)
{
switch (e.ModificationType)
{
case VcModificationTypes.vcAnything:
//Node modified by Inplace Editor
SetNodeEndDate(e.Node);
break;
default:
break;
}
}
If API Changed the data value , Must be explicitly called SetNodeEndDate(...) Method .

next step
You want to continue programming the application , Instead of waiting for the next sequence in our blog series ? We support you by providing a very comprehensive developer's Manual , We strongly recommend the use of . besides , You can also download our free white paper , It provides 11 Best practice tips , Including code snippets :
This article is reprinted from 【 Huidu technology 】. Any reprint is welcome , But be sure to indicate the source 、 Do not modify the original link , Respect for the work of others
版权声明
本文为[roffey]所创,转载请带上原文链接,感谢
边栏推荐
- STM32F030F4P6兼容灵动微MM32F031F4P6
- The first choice for lightweight GPU applications is the NVIDIA vgpu instance launched by Jingdong Zhilian cloud
- The role of theme music in games
- List to map (split the list according to the key, and the value of the same key is a list)
- win7 APPCRASH(解决方法)(转)
- What the hell is fastthreadlocal? The existence of ThreadLocal!!
- The memorandum model of behavior model
- Python 100 cases
- Summary of common SQL statements
- Code generator plug-in and creator preform file analysis
猜你喜欢
vue3 新特性
Interviewer: how about shardingsphere
汽车维修app开发的好处与功能
细数软件工程----各阶段必不可少的那些图
JS array the usage of array is all here (array method reconstruction, array traversal, array de duplication, array judgment and conversion)
Reserved battery interface, built-in charge and discharge circuit and electricity meter, quickly help easily handle hand-held applications
1万辆!理想汽车召回全部缺陷车:已发生事故97起,亏损将扩大
Application of UHF RFID medical blood management system
2020-08-19:TCP是通过什么机制保障可靠性的?
Practice of Xiaoxiong school development board: real equipment access of smart street lamp sandbox experiment
随机推荐
超高频RFID医疗血液管理系统应用
Plug in bilibilibili new version 0.5.5
Common syntax corresponding table of mongodb and SQL
Design of NAND flash interface control
The 4th China BIM (digital construction) manager Summit Forum will be held in Hangzhou in 2020
The native API of the future trend of the front end: web components
A concise tutorial for Nacos, ribbon and feign
What grammar is it? ]
Benefits and functions of auto maintenance app development
Utility class functions (continuous update)
小熊派开发板实践:智慧路灯沙箱实验之真实设备接入
Configuration of AP hotspot on xunwei-imx6ull development board
2020-08-29: process thread differences, in addition to the inclusion relationship, the underlying details?
汽车维修app开发的好处与功能
Two dimensional code location and alarm system of Expressway
消防器材RFID固定资产管理系统
心理咨询app开发所具备的优点与功能
Stm32f030f4p6 compatible with smart micro mm32f031f4p6
Call analysis of start method in JNI thread and callback analysis of run method
ImageMagick - 添加水印