property Chart.AllowCreateBar as CreateBarEnum
Allows creating new bars using the mouse.

TypeDescription
CreateBarEnum A CreateBarEnum expression that indicates whether the user can create new bars using the mouse.
By default, the AllowCreateBar property is exCreateBarManual. Use the AllowCreateBar property to disable creating new bars using the mouse. The control fires the CreateBar event when the user releases the mouse in the chart area. The CreateBar event is fired only if the AllowCreateBar property is not zero. The control prevents creating new bars inside disable items, so you can not create new bars in disabled items. The EnableItem property specifies whether an item is enabled or disabled. The ItemBar(,,exBarsCount) property counts the number of bars in giving item

 

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 VB6 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 VB6 sample prevents creating new tasks/bars on rows/items that already contain bars:

Private Sub G2antt1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim i, c As Long, hit As HitTestInfoEnum
    With G2antt1
        Dim nAllowCreateBar As CreateBarEnum
        nAllowCreateBar = exCreateBarAuto
            i = .ItemFromPoint(-1, -1, c, hit)
            If (i <> 0) Then
                If Not (0 = .Items.ItemBar(i, "<*>", exBarsCount)) Then
                    nAllowCreateBar = exNoCreateBar
                End If
            End If
        .Chart.AllowCreateBar = nAllowCreateBar
    End With
End Sub

The following VB6 sample allows creating bars on leaf items only ( items with no children )

Private Sub G2antt1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Dim i, c As Long, hit As HitTestInfoEnum
    With G2antt1
        Dim nAllowCreateBar As CreateBarEnum
        nAllowCreateBar = exCreateBarAuto
            i = .ItemFromPoint(-1, -1, c, hit)
            If (i <> 0) Then
                If Not .Items.ChildCount(i) = 0 Then
                    nAllowCreateBar = exNoCreateBar
                End If
            End If
        .Chart.AllowCreateBar = nAllowCreateBar
    End With
End Sub

The following VB6 sample disables or prevents creating bars inside specific items ( items with no parent ):

Private Sub G2antt1_CreateBar(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal DateStart As Date, ByVal DateEnd As Date)
    With G2antt1.Items
        If (.ItemParent(Item) = 0) Then
            .RemoveBar Item, "newbar"
        End If
    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