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, or two create a link between two bars. The AddLink method adds the link not matter of the ItemBar(exBarCanBeLinked), ItemBar(exBarCanStartLink), ItemBar(exBarCanEndLink) properties. Use the Link( exLinkGroupBars) to group two linked bars. Use the GroupBars method to group two bars so you can move or resize together when a change occurs in the group. Use the AllowLinkBars property to specify whether the user can link bars using the mouse. 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(exLinkText) property to display a HTML text/icon or picture on the link. 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:

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

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

COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
m_g2antt.BeginUpdate();
CItems items = m_g2antt.GetItems();
CChart chart = m_g2antt.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_g2antt.EndUpdate();

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

AxG2antt1.BeginUpdate()
Dim d As Date = AxG2antt1.Chart.FirstVisibleDate
With AxG2antt1.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
AxG2antt1.EndUpdate()

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

axG2antt1.BeginUpdate();
DateTime d = Convert.ToDateTime(axG2antt1.Chart.FirstVisibleDate);
EXG2ANTTLib.Items spItems = axG2antt1.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");
axG2antt1.EndUpdate();

The following VFP sample adds a link between two bars:

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


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