method Items.AddLink (LinkKey as Variant, StartItem as HITEM, StartBarKey as Variant, EndItem as HITEM, EndBarKey as Variant)
Links a bar to another.

 TypeDescription 
   LinkKey as Variant A String expression that indicates the key of the link. This value is used to identify the link.  
   StartItem as HITEM A HITEM expression that indicates the handle of the item where the link starts.  
   StartBarKey as Variant A String expression that indicates the key of the bar in the StartItem where the link starts.  
   EndItem as HITEM A HITEM expression that indicates the handle of the item where the link ends.  
   EndBarKey as Variant A String expression that indicates the key of the bar in the EndItem where the link ends.  
Use the AddLink method to draw a line between two bars. By default, the bar is drawn from the right side of the starting bar, to the left side of the ending bar. Use the Link(exLinkStartPos) property to change where the link starts in the starting bar. Use the Link(exLinkEndPos) property to change where the link starts in the starting bar. Use the AddBar method to add new bars to an item. Use the Link property to change the appearance of the line between bars. Use the ShowLinks property to hide all links in the chart area. Use the ClearLinks method to clear the links collection. The AddLink method fails, if the StartItem or EndItem item is not valid, or if the StartBarKey or EndBarKey bar does not exist. Use the LinkColor property to change the color for all links between bars. Use the Link(exLinkShowDir) property to hide the link's arrow. Use the RemoveLink method to remove a specific link. Use the BeginUpdate and EndUpdate methods to maintain performance while adding columns, items, bars or links. Use the FirstLink and NextLink properties to enumerate the links in the control.

The following VB sample adds a link between two bars:

Gantt1.BeginUpdate
With Gantt1.Items
    Dim h1 As HITEM
    h1 = .AddItem("Item 1")
    .AddBar h1, "Task", Gantt1.Chart.FirstVisibleDate + 2, Gantt1.Chart.FirstVisibleDate + 4
    Dim h2 As HITEM
    h2 = .AddItem("Item 2")
    .AddBar h2, "Task", Gantt1.Chart.FirstVisibleDate + 1, Gantt1.Chart.FirstVisibleDate + 2, "A"
    .AddLink "Link11", h1, "", h2, "A"
End With
Gantt1.EndUpdate 

The following C++ sample adds a link between two bars:

COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
m_gantt.BeginUpdate();
CItems items = m_gantt.GetItems();
CChart chart = m_gantt.GetChart();
long h1 = items.AddItem( COleVariant( "Item1" ) );
items.AddBar( h1, COleVariant( "Task" ), COleVariant( V_DATE(&chart.GetFirstVisibleDate()) + 2 ), COleVariant( V_DATE(&chart.GetFirstVisibleDate()) + 4 ), vtMissing, vtMissing );
long h2 = items.AddItem( COleVariant( "Item2" ) );
items.AddBar( h2, COleVariant( "Task" ), COleVariant( V_DATE(&chart.GetFirstVisibleDate()) + 1 ), COleVariant( V_DATE(&chart.GetFirstVisibleDate()) + 2 ), COleVariant("JustAKey"), vtMissing );
items.AddLink( COleVariant( "Link1" ), h1, vtMissing, h2, COleVariant("JustAKey") );
m_gantt.EndUpdate();

The following VB.NET sample adds a link between two bars:

AxGantt1.BeginUpdate()
Dim d As Date = AxGantt1.Chart.FirstVisibleDate
With AxGantt1.Items
    Dim h1 As Integer = .AddItem("Item 1")
    .AddBar(h1, "Task", d.AddDays(2), d.AddDays(4))
    Dim h2 As Integer = .AddItem("Item 2")
    .AddBar(h2, "Task", d.AddDays(1), d.AddDays(2), "A")
    .AddLink("Link11", h1, "", h2, "A")
End With
AxGantt1.EndUpdate()

The following C# sample adds a link between two bars:

axGantt1.BeginUpdate();
DateTime d = Convert.ToDateTime(axGantt1.Chart.FirstVisibleDate);
EXGANTTLib.Items spItems = axGantt1.Items;
int h1 = spItems.AddItem("Item 1");
spItems.AddBar(h1, "Task", d.AddDays(2), d.AddDays(4) , null, null);
int h2 = spItems.AddItem("Item 2");
spItems.AddBar(h2, "Task", d.AddDays(1), d.AddDays(2), "A", null);
spItems.AddLink("Link1", h1, null, h2, "A");
axGantt1.EndUpdate();

The following VFP sample adds a link between two bars:

thisform.Gantt1.BeginUpdate
local d
d = thisform.Gantt1.Chart.FirstVisibleDate
With thisform.Gantt1.Items
    local h1
	.DefaultItem = .AddItem("Item 1")
	h1 = .DefaultItem
    .AddBar(0, "Task", thisform.Gantt1.Chart.NextDate(d,4096,2), thisform.Gantt1.Chart.NextDate(d,4096,4))
    local h2
    .DefaultItem = .AddItem("Item 2")
    h2 = .DefaultItem
    .AddBar(0, "Task", thisform.Gantt1.Chart.NextDate(d,4096,1), thisform.Gantt1.Chart.NextDate(d,4096,2), "A")
    .AddLink("Link11", h1, "", h2, "A")
EndWith
thisform.Gantt1.EndUpdate
 


Send comments on this topic.
1999-2017 Exontrol.COM, Software. All rights reserved.