![]() | Type | Description | ||
| Item as HITEM | A HITEM expression that indicates the handle of the item where the bar is created. | |||
| DateStart as Date | A DATE expression that indicates where the bar starts. | |||
| DateEnd as Date | A DATE expression that indicates where the bar ends. |

If the AllowCreateBar property is exCreateBarAuto, the following samples change the key and the type of the bar being displayed as soon as the CreateBar event is called:
The following VB sample changes the key of the newly created bar "newbar", and the name of the bar being displayed as "Task" to "Progress":
Private Sub G2antt1_CreateBar(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal DateStart As Date, ByVal DateEnd As Date)
With G2antt1.Items
.ItemBar(Item, "newbar", exBarName) = "Progress"
.ItemBar(Item, "newbar", exBarKey) = DateStart
End With
End Sub
The following C# sample changes the key of the newly created bar "newbar", and the name of the bar being displayed as "Task" to "Progress":
private void axG2antt1_CreateBar(object sender, AxEXG2ANTTLib._IG2anttEvents_CreateBarEvent e)
{
axG2antt1.Items.set_ItemBar(e.item, "newbar", EXG2ANTTLib.ItemBarPropertyEnum.exBarName, "Progress");
axG2antt1.Items.set_ItemBar(e.item, "newbar", EXG2ANTTLib.ItemBarPropertyEnum.exBarKey, e.dateStart );
}
The following VB.NET sample changes the key of the newly created bar "newbar", and the name of the bar being displayed as "Task" to "Progress":
Private Sub AxG2antt1_CreateBar(ByVal sender As System.Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_CreateBarEvent) Handles AxG2antt1.CreateBar
With AxG2antt1.Items
.ItemBar(e.item, "newbar", EXG2ANTTLib.ItemBarPropertyEnum.exBarName) = "Progress"
.ItemBar(e.item, "newbar", EXG2ANTTLib.ItemBarPropertyEnum.exBarKey) = e.dateStart
End With
End Sub
The following C++ sample changes the key of the newly created bar "newbar", and the name of the bar being displayed as "Task" to "Progress":
void OnCreateBarG2antt1(long Item, DATE DateStart, DATE DateEnd)
{
CItems items = m_g2antt.GetItems();
items.SetItemBar( Item, COleVariant( _T("newbar") ), 0 /*exBarName*/, COleVariant( _T("Progress") ) );
items.SetItemBar( Item, COleVariant( _T("newbar") ), 9 /*exBarKey*/, COleVariant( DateStart ) );
}
The following VFP sample changes the key of the newly created bar "newbar", and the name of the bar being displayed as "Task" to "Progress":
*** ActiveX Control Event *** LPARAMETERS item, datestart, dateend with thisform.G2antt1.Items .DefaultItem = item thisform.G2antt1.Template = "Items.ItemBar(0,`newbar`,0) = `Progress`" thisform.G2antt1.Template = "Items.ItemBar(0,`newbar`,9) = `" + dtos(datestart) + "`" endwith
The Template property helps you to call any of the control's property using x-script.
If the AllowCreateBar property is exCreateBarManual, the following samples adds a new task bar, as soon as the CreateBar is called:
The following C# sample adds a new task, when the user releases the mouse:
private void axG2antt1_CreateBar(object sender, AxEXG2ANTTLib._IG2anttEvents_CreateBarEvent e)
{
Random randomKey = new Random();
axG2antt1.BeginUpdate();
axG2antt1.Items.AddBar(e.item, "Task", e.dateStart, e.dateEnd, randomKey.Next(), "");
axG2antt1.EndUpdate();
}
The following C++ sample adds a new task, when the user releases the mouse:
void OnCreateBarG2antt1(long Item, DATE DateStart, DATE DateEnd)
{
m_g2antt.BeginUpdate();
CItems items = m_g2antt.GetItems();
items.AddBar( Item, COleVariant( "Task" ), COleVariant( DateStart ), COleVariant( DateEnd ), COleVariant( (long)rand() ), COleVariant( "" ) );
m_g2antt.EndUpdate();
}
The following VB sample adds a new task, when the user releases the mouse:
Private Sub G2antt1_CreateBar(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal DateStart As Date, ByVal DateEnd As Date)
With G2antt1
.BeginUpdate
With .Items
.AddBar Item, "Task", DateStart, DateEnd, Rnd
End With
.EndUpdate
End With
End Sub
The following VFP sample adds a new task, when the user releases the mouse:
*** ActiveX Control Event *** LPARAMETERS item, datestart, dateend with thisform.G2antt1 .BeginUpdate with .Items .AddBar( item, "Task", datestart, dateend, RAND() ) endwith .EndUpdate endwith
The following VB.NET sample adds a new task, when the user releases the mouse:
Private Sub AxG2antt1_CreateBar(ByVal sender As Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_CreateBarEvent) Handles AxG2antt1.CreateBar
With AxG2antt1
.BeginUpdate()
With .Items
.AddBar(e.item, "Task", e.dateStart, e.dateEnd, Rnd())
End With
.EndUpdate()
End With
End Sub