method Items.AddBar (Item as HITEM, BarName as Variant, DateStart as Variant, DateEnd as Variant, [Key as Variant], [Text as Variant])
Adds a bar to an item.

 TypeDescription 
   Item as HITEM A long expression that indicates the the handle of the item where the bar is inserted.  
   BarName as Variant A String expression that indicates the name of the bar being inserted, or a long expression that indicates the index of the bar being inserted  
   DateStart as Variant A Date expression that indicates the date/time where the bar starts, or a string expression that indicates the start date and time. For instance, the "6/10/2003 10:13", indicates the date and the time.   
   DateEnd as Variant A Date expression that indicates the date where the bar ends, or a string expression that indicates the end date and time. For instance, the "6/10/2003 10:13", indicates the date and the time.  
   Key as Variant Optional. A String expression that indicates the key of the bar being inserted. If missing, the Key parameter is empty. If the Item has only a single Bar you can not use the Key parameter, else an unique key should be used.  
   Text as Variant Optional. A String expression that indicates the text being displayed. The Text may include built-in HTML format. Use the ItemBar(exBarHAlignCaption/exBarVAlignCaption) to display and align the caption of the bar inside or outside of the bar.  
Use the AddBar property to add a bar to an item. Use the ShowEmptyBars property to show the bars, even if the start and end dates are identical. If you want to assign multiple bars to the same items, you have to use different keys ( Key parameter ), else the default bar is overwritten. More than that, if the DateStart and DateEnd are identical, the bar or text is not shown, except the Milestone bar. Use the Add method to add new types of bars to the Bars collection. Use the FirstVisibleDate property to specify the first visible date in the chart area. Use the Key parameter to identify a bar inside an item. If the AddBar method is called multiple time with the same item, the bar is moved. Use the ItemBar property to access a bar inside the item. Use the RemoveBar method to remove a bar from an item. Use the ClearBars method to remove all bars in the item. Use the PaneWidth property to specify the width of the chart. Use the NonworkingDays property to specify the non-working days. Use the NextDate property to compute the next or previous date based on a time unit. Use the ItemBar(exBarToolTip) property to assign a tooltip to a bar. Use the ItemBar(exBarBackColor) property to change the background or the visual appearance for the portion delimited by the start and end points. Use the FirstItemBar and NextItemBar methods to enumerate the bars inside the item. Use the Height property to specify the height of the bars. Use the ItemBar(exBarsCount) property to retrieve the number of bars in a specified item.

The following VB sample adds a "Milestone" bar and a text beside:

With Gantt1.Items
    h = .AddItem("new task")
    .AddBar h, "Milestone", "5/30/2005 10:00", "5/31/2005"
    .AddBar h, "", "5/31/2005", "6/10/2005", "beside", "<fgcolor=FF0000><b>item</b></fgcolor> to change"
End With

or

With Gantt1.Items
    .AddBar .AddItem("new task"), "Milestone", "5/30/2005 10:00", "6/10/2005", , "   <fgcolor=FF0000><b>item</b></fgcolor> to change"
End With

The following VB sample adds an item with a single "Task" bar:

Dim h As HITEM, d As Date
With Gantt1.Items
    d = Gantt1.Chart.FirstVisibleDate
    h = .AddItem("new task")
    .AddBar h, "Task", Gantt1.Chart.NextDate(d, exDay, 2), Gantt1.Chart.NextDate(d, exDay, 4)
End With

The following VB sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like ):

Dim h As HITEM, d As Date
With Gantt1.Items
    d = Gantt1.Chart.FirstVisibleDate
    h = .AddItem("new task ")
    .AddBar h, "Task", d + 2, d + 4, "K1"
    .AddBar h, "Split", d + 4, d + 5, "K2"
    .AddBar h, "Task", d + 5, d + 9, "K3"
End With

The bar is composed by three parts: K1, K2 and K3.

The following C++ sample adds a "Milestone" bar and a text beside:

#include "Items.h"
COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
CItems items = m_gantt.GetItems();
long h = items.AddItem( COleVariant( "new task" ) );
items.AddBar( h, COleVariant("Milestone"), COleVariant( "5/30/2005 10:00" ), COleVariant( "5/31/2005" ), vtMissing, vtMissing );
items.AddBar( h, COleVariant(""), COleVariant( "5/31/2005" ), COleVariant( "6/10/2005" ), COleVariant( _T("just a key") ), COleVariant( "<fgcolor=FF0000><b>item</b></fgcolor> to change" ) );

or

#include "Items.h"
COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
CItems items = m_gantt.GetItems();
long h = items.AddItem( COleVariant( "new task" ) );
items.AddBar( h, COleVariant("Milestone"), COleVariant( "5/30/2005 10:00" ), COleVariant( "6/10/2005" ), vtMissing, COleVariant( "    <fgcolor=FF0000><b>item</b></fgcolor> to change" ) );

The following C++ sample adds an item with a single "Task" bar:

COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
CItems items = m_gantt.GetItems();
CChart chart = m_gantt.GetChart();
DATE d = V2D( &chart.GetFirstVisibleDate() );
long h = items.AddItem( COleVariant("new task") );
items.AddBar( h, COleVariant( "Task"), COleVariant( (double)chart.GetNextDate( d, 4096, COleVariant((long)2) ) ), COleVariant( (double)chart.GetNextDate( d, 4096, COleVariant((long)4) ) ), vtMissing , vtMissing );

The following C++ sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:

COleVariant vtMissing; V_VT( &vtMissing ) = VT_ERROR;
CItems items = m_gantt.GetItems();
DATE d = V2D( &m_gantt.GetChart().GetFirstVisibleDate() );
long h = items.AddItem( COleVariant("new task") );
items.AddBar( h, COleVariant( "Task"), COleVariant( d + 2 ), COleVariant( d + 4 ), COleVariant( "K1" ), vtMissing );
items.AddBar( h, COleVariant( "Split"), COleVariant( d + 4 ), COleVariant( d + 5 ), COleVariant( "K2" ), vtMissing );
items.AddBar( h, COleVariant( "Task"), COleVariant( d + 5 ), COleVariant( d + 9 ), COleVariant( "K3" ), vtMissing );

where the V2D function converts a Variant expression to a DATE expression and may look like follows:

static DATE V2D( VARIANT* pvtDate )
{
	COleVariant vtDate;
	vtDate.ChangeType( VT_DATE, pvtDate );
	return V_DATE( &vtDate );
}

The following VB.NET sample adds a "Milestone" bar and a text beside:

With AxGantt1.Items
    Dim h As Integer = .AddItem("new task")
    .AddBar(h, "Milestone", "5/30/2005 10:00", "5/31/2005")
    .AddBar(h, "", "5/31/2005", "6/10/2005", "beside", "<fgcolor=FF0000><b>item</b></fgcolor> to change")
End With

or

With AxGantt1.Items
    Dim h As Integer = .AddItem("new task")
    .AddBar(h, "Milestone", "5/30/2005 10:00", "6/10/2005", , "   <fgcolor=FF0000><b>item</b></fgcolor> to change")
End With

The following VB.NET sample adds an item with a single "Task" bar:

With AxGantt1.Items
    Dim d As DateTime = AxGantt1.Chart.FirstVisibleDate
    Dim h As Integer = .AddItem("new task")
    .AddBar(h, "Task", AxGantt1.Chart.NextDate(d, EXGANTTLib.UnitEnum.exDay, 2), AxGantt1.Chart.NextDate(d, EXGANTTLib.UnitEnum.exDay, 4))
End With

The following VB.NET sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:

With AxGantt1.Items
    Dim d As DateTime = AxGantt1.Chart.FirstVisibleDate
    Dim h As Integer = .AddItem("new task ")
    .AddBar(h, "Task", d.AddDays(2), d.AddDays(4), "K1")
    .AddBar(h, "Split", d.AddDays(4), d.AddDays(5), "K2")
    .AddBar(h, "Task", d.AddDays(5), d.AddDays(9), "K3")
End With

The following C# sample adds a "Milestone" bar and a text beside:

EXGANTTLib.Items items = axGantt1.Items;
int h = items.AddItem("new task");
items.AddBar(h, "Milestone", "5/30/2005 10:00", "5/31/2005", null, null);
items.AddBar(h, "", "5/31/2005", "6/10/2005", "just a new key", "<fgcolor=FF0000><b>item</b></fgcolor> to change");

or

EXGANTTLib.Items items = axGantt1.Items;
int h = items.AddItem("new task");
items.AddBar(h, "Milestone", "5/30/2005 10:00", "6/10/2005", null, "   <fgcolor=FF0000><b>item</b></fgcolor> to change");

The following C# sample adds an item with a single "Task" bar:

EXGANTTLib.Items items = axGantt1.Items;
int h = items.AddItem("new task");
DateTime d = Convert.ToDateTime(axGantt1.Chart.FirstVisibleDate);
items.AddBar(h, "Task", axGantt1.Chart.get_NextDate(d, EXGANTTLib.UnitEnum.exDay, 2), axGantt1.Chart.get_NextDate(d, EXGANTTLib.UnitEnum.exDay, 4), null, null);

The following C# sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:

EXGANTTLib.Items items = axGantt1.Items;
int h = items.AddItem("new task");
DateTime d = Convert.ToDateTime( axGantt1.Chart.FirstVisibleDate );
items.AddBar(h, "Task", d.AddDays(2), d.AddDays(4), "K1", null );
items.AddBar(h, "Split", d.AddDays(4), d.AddDays(5), "K2", null);
items.AddBar(h, "Task", d.AddDays(5), d.AddDays(9), "K3", null);

The following VFP sample adds an item with a single "Task" bar:

With thisform.Gantt1.Items
	d = thisform.Gantt1.Chart.FirstVisibleDate
	.DefaultItem = .AddItem("new task")
	.AddBar(0, "Task", thisform.Gantt1.Chart.NextDate(d,4096,2), thisform.Gantt1.Chart.NextDate(d,4096,4))
EndWith

The following VFP sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:

With thisform.Gantt1.Items
	thisform.Gantt1.Chart.FirstVisibleDate = "5/29/2005"
    .DefaultItem = .AddItem("new task")
    .AddBar(0, "Task", "5/31/2005", "6/2/2005", "K1", "")
    .AddBar(0, "Split", "6/2/2005", "6/4/2005", "K2", "")
    .AddBar(0, "Task", "6/4/2005", "6/9/2005", "K3", "")
EndWith

 


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