Tips & Tricks: Two Entities of VARCHART XGantt On One Form

Posted by Martin Karlowitsch on Oct 25, 2011 12:33:00 PM

If you want to display two entities of XGantt on one form, you should use a SplitContainer. A SplitContainer is a control that consists of two panels, the proportions of which to one another can be modified interactively at runtime by a splitter between them. Using a splitter makes sense if, for instance, many unscheduled tasks are displayed one below the other.

If the two entities of XGantt are mounted on the two panels of the SplitContainer, the entities' width to height ratio to one another can be modified interactively.




 


To create a neat picture, the settings of the table width and the time scale should be the same for both XGantts. In addition, you should disable the horizontal scroll bar of the upper chart and the time scale of the lower chart so that there will be more room left for displaying the data. As the horizontal scrolling of the upper chart is then no longer possible, you need the following code to ensure the simultaneous scrolling of the upper chart in case the scroll bar of the lower chart will be moved (vcGantt1 being the upper, vcGantt2 the lower chart):

private void vcGantt2_VcDiagramHorizontalScrolled(object sender,
VcDiagramHorizontalScrolledEventArgs e)
{
vcGantt1.FitRangeIntoView(e.CurStartDate, e.CurEndDate, 0);
}

The interactive modification of the time scale solution (unit width) in the upper chart requires a reaction as well (if this interaction has not been disabled in general):

private void vcGantt1_VcTimeScaleSectionRescaling(object sender,
VcTimeScaleSectionRescalingEventArgs e)
{

DateTime leftDate = new DateTime(1,1,1);
DateTime rightDate = new DateTime(1,1,1);
int minBasicUnitWidth = 75;          //May have to be adjusted
if (e.NewBasicUnitWidth < 75);
{
e.TimeScale.get_Section((short)e.SectionIndex).UnitWidth = minBasicUnitWidth;
vcGantt2.TimeScaleCollection.Active.get_Section((short)e.SectionIndex).UnitWidth
= minBasicUnitWidth;
e.ReturnStatus = VcReturnStatus.vcRetStatFalse;

}
else
vcGantt2.TimeScaleCollection.Active.get_Section((short)e.SectionIndex).UnitWidth
= e.NewBasicUnitWidth;
vcGantt1.GetCurrentViewDates(ref leftDate, ref rightDate);
.ScrollToDate(leftDate, VcHorizontalAlignment.vcLeftAligned, 0);
}
The following code is needed to respond to the interactive moving of the splitter between the table and the diagram of the two charts:

private void vcGantt1_VcTableWidthChanging(object sender, VcTableWidthChangingEventArgs e)
{
vcGantt2.LeftTableDiagramWidthRatio = (short)e.TableDiagramWidthRatio;
}
private void vcGantt2_VcTableWidthChanging(object sender, VcTableWidthChangingEventArgs e)
{
vcGantt1.LeftTableDiagramWidthRatio = (short)e.TableDiagramWidthRatio;
}



Topics: Windows Forms Gantt Control, Gantt Chart Controls