![]() | Type | Description | ||
| 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. |

![]()
The Color property of the Bar object specifies the color being used to paint the bar. This property changes the colors for all bars with the same name. For instance, if you have 3 "Task" bars, and you are changing the color for the "Task" bar, the color is applied to all "Task" bars in the chart. For instance, in order to provide "Task" bars with different colors, you can use the Copy method to copy the Task bar to a new bar, and use the Color to change the color of the bar. The following function generates a Task bar with specified color:
Private Function AddTask(ByVal gantt As EXG2ANTTLibCtl.G2antt, ByVal clr As Long) As String
Dim sT As String
sT = "Task:" & clr
With gantt.Chart.Bars.Copy("Task", sT)
.color = clr
End With
AddTask = sT
End Function
The function generates a new bar with the name "Task:color", where the color is the color being used, and retrieves the name of the new bar being added. The Copy method retrieves the bar being found with specified name, or creates a new bar if the name is not found in the Bars collection, so AddTask function gets you the name of the bar you should use to specify the color for the bar being added as in the following sample:
With G2antt1.Items Dim d As Date d = G2antt1.Chart.FirstVisibleDate .AddBar .FirstVisibleItem, AddTask(G2antt1, vbRed), d, d + 4, "Red" End With
The following VB sample adds a "Milestone" bar and a text beside:
With G2antt1.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 G2antt1.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 G2antt1.Items
d = G2antt1.Chart.FirstVisibleDate
h = .AddItem("new task")
.AddBar h, "Task", G2antt1.Chart.NextDate(d, exDay, 2), G2antt1.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 G2antt1.Items
d = G2antt1.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_g2antt.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_g2antt.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_g2antt.GetItems();
CChart chart = m_g2antt.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_g2antt.GetItems();
DATE d = V2D( &m_g2antt.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 AxG2antt1.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 Withor
With AxG2antt1.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 WithThe following VB.NET sample adds an item with a single "Task" bar:
With AxG2antt1.Items
Dim d As DateTime = AxG2antt1.Chart.FirstVisibleDate
Dim h As Integer = .AddItem("new task")
.AddBar(h, "Task", AxG2antt1.Chart.NextDate(d, EXG2ANTTLib.UnitEnum.exDay, 2), AxG2antt1.Chart.NextDate(d, EXG2ANTTLib.UnitEnum.exDay, 4))
End WithThe following VB.NET sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:
With AxG2antt1.Items
Dim d As DateTime = AxG2antt1.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 WithThe following C# sample adds a "Milestone" bar and a text beside:
EXG2ANTTLib.Items items = axG2antt1.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
EXG2ANTTLib.Items items = axG2antt1.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:
EXG2ANTTLib.Items items = axG2antt1.Items;
int h = items.AddItem("new task");
DateTime d = Convert.ToDateTime(axG2antt1.Chart.FirstVisibleDate);
items.AddBar(h, "Task", axG2antt1.Chart.get_NextDate(d, EXG2ANTTLib.UnitEnum.exDay, 2), axG2antt1.Chart.get_NextDate(d, EXG2ANTTLib.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:
EXG2ANTTLib.Items items = axG2antt1.Items;
int h = items.AddItem("new task");
DateTime d = Convert.ToDateTime( axG2antt1.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.G2antt1.Items
d = thisform.G2antt1.Chart.FirstVisibleDate
.DefaultItem = .AddItem("new task")
.AddBar(0, "Task", thisform.G2antt1.Chart.NextDate(d,4096,2), thisform.G2antt1.Chart.NextDate(d,4096,4))
EndWithThe following VFP sample adds an item with three bars ( two "Task" bars, and one "Split" bar ) that looks like above:
With thisform.G2antt1.Items
thisform.G2antt1.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