event BarParentChange (Item as HITEM, Key as Variant, NewItem as HITEM, Cancel as Boolean)
Occurs just before moving a bar from current item to another item.

 TypeDescription 
   Item as HITEM A long expression that specifies the owner item ( the handle ) that displays the bar being moved.  
   Key as Variant A string/variant expression that specifies the key of the bar being moved.  
   NewItem as HITEM A long expression that specifies the handle of the item where the bar is going to be moved.  
   Cancel as Boolean A boolean expression that indicates where the bar can be moved from Item to NewItem.  By default, the Cancel parameter is False, so the bar can be moved to any item that does not contain another bar with the same key. Handle the event, and change the Cancel parameter to False, if you need to prevent moving a bar to NewItem item.   
The BarParentChange event notifies your application when a bar is about to be moved from an item to another item. Use the BarParentChange event to control the items where the bar can be moved through the items. The ItemBar(exBarCanMoveToAnother) property specifies whether the user can drag and drop a bar from an item to another item. The ItemBar(exBarCanMove) property specifies whether the user can moves the bar to a new position inside the bar. The ItemBar(exBarParent) property specifies the handle of the item that displays the bar. Use the ItemBar(exBarParent) property to change programmatically the parent of the specified bar. The control fires the BarResize event when the bar is resized or moved to a new position inside the item. The BarParentChange event is fired during the drag and drop operation as soon as the user moves the bar's parent, but it is fired also one more time once the user releases the left mouse button. You can use the GetAsyncKeyState API function to determine whether the left mouse button is pressed or released as in the following VB sample. The ChartEndChanging(exBarMoveBar) event occurs once the user ends the UI operation like moving a bar. 

The following screen shot shows few options to move, limit or resize bars:

The screen show was generate using the following x-script template ( the visual appearance code was excluded ):

Syntax for BarParentChange event, /NET version, on:

private void BarParentChange(object sender,int Item,object Key,int NewItem,ref bool Cancel)
{
}

Private Sub BarParentChange(ByVal sender As System.Object,ByVal Item As Integer,ByVal Key As Object,ByVal NewItem As Integer,ByRef Cancel As Boolean) Handles BarParentChange
End Sub

Syntax for BarParentChange event, /COM version, on:

private void BarParentChange(object sender, AxEXG2ANTTLib._IG2anttEvents_BarParentChangeEvent e)
{
}

void OnBarParentChange(long Item,VARIANT Key,long NewItem,BOOL FAR* Cancel)
{
}

void __fastcall BarParentChange(TObject *Sender,Exg2anttlib_tlb::HITEM Item,Variant Key,Exg2anttlib_tlb::HITEM NewItem,VARIANT_BOOL * Cancel)
{
}

procedure BarParentChange(ASender: TObject; Item : HITEM;Key : OleVariant;NewItem : HITEM;var Cancel : WordBool);
begin
end;

procedure BarParentChange(sender: System.Object; e: AxEXG2ANTTLib._IG2anttEvents_BarParentChangeEvent);
begin
end;

begin event BarParentChange(long Item,any Key,long NewItem,boolean Cancel)
end event BarParentChange

Private Sub BarParentChange(ByVal sender As System.Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_BarParentChangeEvent) Handles BarParentChange
End Sub

Private Sub BarParentChange(ByVal Item As EXG2ANTTLibCtl.HITEM,ByVal Key As Variant,ByVal NewItem As EXG2ANTTLibCtl.HITEM,Cancel As Boolean)
End Sub

Private Sub BarParentChange(ByVal Item As Long,ByVal Key As Variant,ByVal NewItem As Long,Cancel As Boolean)
End Sub

LPARAMETERS Item,Key,NewItem,Cancel

PROCEDURE OnBarParentChange(oG2antt,Item,Key,NewItem,Cancel)
RETURN

Syntax for BarParentChange event, /COM version (others), on:

<SCRIPT EVENT="BarParentChange(Item,Key,NewItem,Cancel)" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function BarParentChange(Item,Key,NewItem,Cancel)
End Function
</SCRIPT>

Procedure OnComBarParentChange HITEM llItem Variant llKey HITEM llNewItem Boolean llCancel
	Forward Send OnComBarParentChange llItem llKey llNewItem llCancel
End_Procedure

METHOD OCX_BarParentChange(Item,Key,NewItem,Cancel) CLASS MainDialog
RETURN NIL

void onEvent_BarParentChange(int _Item,COMVariant _Key,int _NewItem,COMVariant /*bool*/ _Cancel)
{
}

function BarParentChange as v (Item as OLE::Exontrol.G2antt.1::HITEM,Key as A,NewItem as OLE::Exontrol.G2antt.1::HITEM,Cancel as L)
end function

function nativeObject_BarParentChange(Item,Key,NewItem,Cancel)
return

The following VB/NET sample shows how to simulate a drop event, in other words how you can get notification once the user drops a bar to another parent ( the sample displays the caption of the new parent, once the user drops the bar to a new parent ):

Dim iMoving As Long = 0
Dim bMoving As Object = Nothing

Private Sub Exg2antt1_BarParentChange(ByVal sender As Object, ByVal Item As Integer, ByVal Key As Object, ByVal NewItem As Integer, ByRef Cancel As Boolean) Handles Exg2antt1.BarParentChange
    iMoving = NewItem
    bMoving = Key
End Sub

Private Sub Exg2antt1_ChartEndChanging(ByVal sender As System.Object, ByVal Operation As exontrol.EXG2ANTTLib.BarOperationEnum) Handles Exg2antt1.ChartEndChanging
    If (Operation = exontrol.EXG2ANTTLib.BarOperationEnum.exMoveBar) Then
        If (iMoving <> 0) Then
            If Not (bMoving Is Nothing) Then
                MessageBox.Show(Exg2antt1.Items.get_CellCaption(Exg2antt1.Items.get_BarParent(iMoving, bMoving), 0)).ToString()
            End If
        End If
        iMoving = 0
        bMoving = Nothing
    End If
End Sub

The following VB sample prevents moving the bar to selectable items only ( SelectableItem property ):

Private Sub G2antt1_BarParentChange(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal Key As Variant, ByVal NewItem As EXG2ANTTLibCtl.HITEM, Cancel As Boolean)
    With G2antt1.Items
        Cancel = Not .SelectableItem(NewItem)
    End With
End Sub

The following VB.NET sample prevents moving the bar to selectable items only ( SelectableItem property ):

Private Sub AxG2antt1_BarParentChange(ByVal sender As System.Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_BarParentChangeEvent) Handles AxG2antt1.BarParentChange
    With AxG2antt1.Items
        e.cancel = Not .SelectableItem(e.newItem)
    End With
End Sub

The following C# sample prevents moving the bar to selectable items only ( SelectableItem property ):

private void axG2antt1_BarParentChange(object sender, AxEXG2ANTTLib._IG2anttEvents_BarParentChangeEvent e)
{
    e.cancel = !axG2antt1.Items.get_SelectableItem(e.newItem);
}

The following C++ sample prevents moving the bar to selectable items only ( SelectableItem property ):

#include "Items.h"
void OnBarParentChangeG2antt1(long Item, const VARIANT FAR& Key, long NewItem, BOOL FAR* Cancel) 
{
	*Cancel = !m_g2antt.GetItems().GetSelectableItem( NewItem );
}

The following VFP sample prevents moving the bar to selectable items only ( SelectableItem property ):

*** ActiveX Control Event ***
LPARAMETERS item, key, newitem, cancel

cancel = !thisform.G2antt1.Items.SelectableItem(newitem)

 


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