event ChartSelectionChanged ()
Occurs when the user selects objects in the chart area.

TypeDescription
The ChartSelectionChanged event notifies your application when the user select objects like bars or links in the chart area. Use the AllowSelectObjects property to specify whether the user can select bars or/and links at runtime, using the mouse.  Use the SelectedObject property to retrieve a collection of selected bars or/and links. Use the ItemBar(exBarSelected) property to select or unselect programmatically a bar. Use the Link(exLinkSelected) property to select or unselect programmatically a link. Use the RemoveSelection property to remove objects in the chart's selection. Use the ExecuteTemplate property to execute and returns the result of a x-script.

Syntax for ChartSelectionChanged event, /NET version, on:

private void ChartSelectionChanged(object sender)
{
}

Private Sub ChartSelectionChanged(ByVal sender As System.Object) Handles ChartSelectionChanged
End Sub

Syntax for ChartSelectionChanged event, /COM version, on:

private void ChartSelectionChanged(object sender, EventArgs e)
{
}

void OnChartSelectionChanged()
{
}

void __fastcall ChartSelectionChanged(TObject *Sender)
{
}

procedure ChartSelectionChanged(ASender: TObject; );
begin
end;

procedure ChartSelectionChanged(sender: System.Object; e: System.EventArgs);
begin
end;

begin event ChartSelectionChanged()
end event ChartSelectionChanged

Private Sub ChartSelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChartSelectionChanged
End Sub

Private Sub ChartSelectionChanged()
End Sub

Private Sub ChartSelectionChanged()
End Sub

LPARAMETERS nop

PROCEDURE OnChartSelectionChanged(oG2antt)
RETURN

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

<SCRIPT EVENT="ChartSelectionChanged()" LANGUAGE="JScript">
</SCRIPT>

<SCRIPT LANGUAGE="VBScript">
Function ChartSelectionChanged()
End Function
</SCRIPT>

Procedure OnComChartSelectionChanged 
	Forward Send OnComChartSelectionChanged 
End_Procedure

METHOD OCX_ChartSelectionChanged() CLASS MainDialog
RETURN NIL

void onEvent_ChartSelectionChanged()
{
}

function ChartSelectionChanged as v ()
end function

function nativeObject_ChartSelectionChanged()
return

The following VB sample displays the list of selected bars:

Private Sub G2antt1_ChartSelectionChanged()
    Dim c As Variant
    For Each c In G2antt1.Items.SelectedObjects(exSelectBarsOnly)
        Debug.Print c
    Next
End Sub

The following VB sample displays only the bars being selected and un-selected since last selection change event:

Private Sub G2antt1_ChartSelectionChanged()
    Dim c As Variant
    With G2antt1
        For Each c In .Items.SelectedObjects(exSelectBarsOnly Or exObjectsJustAdded)
            Debug.Print "Added " & .ExecuteTemplate("Items.ItemBar(" & c & "," & exBarName & ")")
        Next
        For Each c In .Items.SelectedObjects(exSelectBarsOnly Or exObjectsJustRemoved)
            Debug.Print "Removed " & .ExecuteTemplate("Items.ItemBar(" & c & "," & exBarName & ")")
        Next
    End With
End Sub

The following VB sample displays the name of the bars being selected:

Private Sub G2antt1_ChartSelectionChanged()
    Dim c As Variant
    With G2antt1
        For Each c In .Items.SelectedObjects(exSelectBarsOnly)
            Debug.Print .ExecuteTemplate("Items.ItemBar(" & c & "," & exBarName & ")")
        Next
    End With
End Sub

The following VB.NET sample displays the list of selected bars:

Private Sub AxG2antt1_ChartSelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxG2antt1.ChartSelectionChanged
	Dim c As String
	For Each c In AxG2antt1.Items.SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly)
	   Debug.Print(c)
	Next
End Sub

The following VB.NET sample displays only the bars being selected and un-selected since last selection change event:

Private Sub AxG2antt1_ChartSelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxG2antt1.ChartSelectionChanged
    Dim c As String
    With AxG2antt1
        For Each c In .Items.SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly Or EXG2ANTTLib.SelectObjectsEnum.exObjectsJustAdded)
            Dim t As String = "Items.ItemBar(" + c + "," + Int(EXG2ANTTLib.ItemBarPropertyEnum.exBarName).ToString() + ")"
            Debug.Print("Added: " + .ExecuteTemplate(t))
        Next
        For Each c In .Items.SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly Or EXG2ANTTLib.SelectObjectsEnum.exObjectsJustRemoved)
            Dim t As String = "Items.ItemBar(" + c + "," + Int(EXG2ANTTLib.ItemBarPropertyEnum.exBarName).ToString() + ")"
            Debug.Print("Removed: " + .ExecuteTemplate(t))
        Next
    End With
End Sub

The following VB.NET sample displays the name of the bars being selected:

Private Sub AxG2antt1_ChartSelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxG2antt1.ChartSelectionChanged
    Dim c As String
    With AxG2antt1
        For Each c In .Items.SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly)
            Dim t As String = "Items.ItemBar(" + c + "," + Int(EXG2ANTTLib.ItemBarPropertyEnum.exBarName).ToString() + ")"
            Debug.Print(.ExecuteTemplate(t))
        Next
    End With
End Sub

The following C# sample displays the list of selected bars:

private void axG2antt1_ChartSelectionChanged(object sender, EventArgs e)
{
    foreach (string c in axG2antt1.Items.get_SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly) as Array ) 
    {
        System.Diagnostics.Debug.WriteLine( c );
    }
}

The following C# sample displays only the bars being selected and un-selected since last selection change event:

private void axG2antt1_ChartSelectionChanged(object sender, EventArgs e)
{
    foreach (string c in axG2antt1.Items.get_SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly | EXG2ANTTLib.SelectObjectsEnum.exObjectsJustAdded) as Array)
    {
        String t = "Items.ItemBar(" + c + "," + ((long)EXG2ANTTLib.ItemBarPropertyEnum.exBarName).ToString() + ")";
        System.Diagnostics.Debug.WriteLine("Added: " + axG2antt1.ExecuteTemplate(t));
    }
    foreach (string c in axG2antt1.Items.get_SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly | EXG2ANTTLib.SelectObjectsEnum.exObjectsJustRemoved) as Array)
    {
        String t = "Items.ItemBar(" + c + "," + ((long)EXG2ANTTLib.ItemBarPropertyEnum.exBarName).ToString() + ")";
        System.Diagnostics.Debug.WriteLine("Removed: " + axG2antt1.ExecuteTemplate(t));
    }
}

The following C# sample displays the name of the bars being selected:

private void axG2antt1_ChartSelectionChanged(object sender, EventArgs e)
{
    foreach (string c in axG2antt1.Items.get_SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly) as Array)
    {
        String t = "Items.ItemBar(" + c + "," + ((long)EXG2ANTTLib.ItemBarPropertyEnum.exBarName).ToString() + ")";
        System.Diagnostics.Debug.WriteLine(axG2antt1.ExecuteTemplate(t));
    }
}

The following C++ sample displays the list of selected bars:

#include "Items.h"
void OnChartSelectionChangedG2antt1() 
{
	COleVariant vtSelected = m_g2antt.GetItems().GetSelectedObjects( 1 ); //exSelectBarsOnly
	if ( V_VT( &vtSelected ) & VT_ARRAY | VT_VARIANT )
	{
		SAFEARRAY* pArray = V_ARRAY( &vtSelected );
		void* pData = NULL;
		if ( SUCCEEDED( SafeArrayAccessData( pArray, &pData ) ) )
		{
			VARIANT* p = (VARIANT*)pData;
			for ( long i = 0; i < (long)pArray->rgsabound[0].cElements ; i++, p++ )
				OutputDebugString( V2S( p ) );
			SafeArrayUnaccessData( pArray );
		}
	}
}

The following C++ sample displays only the bars being selected and un-selected since last selection change event:

void OnChartSelectionChangedG2antt1() 
{
	COleVariant vtAdded = m_g2antt.GetItems().GetSelectedObjects( 1 /*exSelectBarsOnly*/ | 0x20 /*exObjectsJustAdded*/ );
	if ( V_VT( &vtAdded ) & VT_ARRAY | VT_VARIANT )
	{
		SAFEARRAY* pArray = V_ARRAY( &vtAdded );
		void* pData = NULL;
		if ( SUCCEEDED( SafeArrayAccessData( pArray, &pData ) ) )
		{
			VARIANT* p = (VARIANT*)pData;
			for ( long i = 0; i < (long)pArray->rgsabound[0].cElements ; i++, p++ )
			{
				CString strT = "Items.ItemBar(" + V2S( p ) + ",0)"; /*builds the Items.ItemBar(Handle,Key,exBarName) template*/
				OutputDebugString( "Added: " + V2S( &m_g2antt.ExecuteTemplate( strT ) ) + "\n" );
			}
			SafeArrayUnaccessData( pArray );
		}
	}
	COleVariant vtRemoved = m_g2antt.GetItems().GetSelectedObjects( 1 /*exSelectBarsOnly*/ | 0x40 /*exObjectsJustRemoved*/ );
	if ( V_VT( &vtRemoved ) & VT_ARRAY | VT_VARIANT )
	{
		SAFEARRAY* pArray = V_ARRAY( &vtRemoved );
		void* pData = NULL;
		if ( SUCCEEDED( SafeArrayAccessData( pArray, &pData ) ) )
		{
			VARIANT* p = (VARIANT*)pData;
			for ( long i = 0; i < (long)pArray->rgsabound[0].cElements ; i++, p++ )
			{
				CString strT = "Items.ItemBar(" + V2S( p ) + ",0)"; /*builds the Items.ItemBar(Handle,Key,exBarName) template*/
				OutputDebugString( "Removed: " + V2S( &m_g2antt.ExecuteTemplate( strT ) ) + "\n" );
			}
			SafeArrayUnaccessData( pArray );
		}
	}
}

The following C++ sample displays the name of the bars being selected:

#include "Items.h"
void OnChartSelectionChangedG2antt1() 
{
	COleVariant vtSelected = m_g2antt.GetItems().GetSelectedObjects( 1 /*exSelectBarsOnly*/ );
	if ( V_VT( &vtSelected ) & VT_ARRAY | VT_VARIANT )
	{
		SAFEARRAY* pArray = V_ARRAY( &vtSelected );
		void* pData = NULL;
		if ( SUCCEEDED( SafeArrayAccessData( pArray, &pData ) ) )
		{
			VARIANT* p = (VARIANT*)pData;
			for ( long i = 0; i < (long)pArray->rgsabound[0].cElements ; i++, p++ )
			{
				CString strT = "Items.ItemBar(" + V2S( p ) + ",0)"; /*builds the Items.ItemBar(Handle,Key,exBarName) template*/
				OutputDebugString( V2S( &m_g2antt.ExecuteTemplate( strT ) ) );
			}
			SafeArrayUnaccessData( pArray );
		}
	}
}

where the V2S string may look like follows:

static CString V2S( VARIANT* pv, LPCTSTR szDefault = _T("") )
{
	if ( pv )
	{
		if ( pv->vt == VT_ERROR )
			return szDefault;

		COleVariant vt;
		vt.ChangeType( VT_BSTR, pv );
		return V_BSTR( &vt );
	}
	return szDefault;
}

or

static string V2S( VARIANT* pv, LPCTSTR szDefault = _T("") )
{
	if ( pv )
	{
		if ( pv->vt == VT_ERROR )
			return szDefault;

		CComVariant vt;
		if ( SUCCEEDED( vt.ChangeType( VT_BSTR, pv ) ) )
		{
			USES_CONVERSION;
			return OLE2T(V_BSTR( &vt ));
		}
	}
	return szDefault;
}

The following VFP sample displays the list of selected bars:

*** ActiveX Control Event ***

local c
For Each c In thisform.G2antt1.Items.SelectedObjects(1)
	wait window c
Next

The following VFP sample displays only the bars being selected and un-selected since last selection change event:

*** ActiveX Control Event ***

local c
For Each c In thisform.G2antt1.Items.SelectedObjects( 1 + 0x20 )
	local t
	t = "Items.ItemBar(" + c + ",0)"
	wait window "Added: " + thisform.G2antt1.ExecuteTemplate(t)
Next
For Each c In thisform.G2antt1.Items.SelectedObjects( 1 + 0x40 )
	local t
	t = "Items.ItemBar(" + c + ",0)"
	wait window "Removed: " + thisform.G2antt1.ExecuteTemplate(t)
Next

The following VFP sample displays the name of the bars being selected:

*** ActiveX Control Event ***

local c
For Each c In thisform.G2antt1.Items.SelectedObjects(1)
	local t
	t = "Items.ItemBar(" + c + ",0)"
	wait window thisform.G2antt1.ExecuteTemplate(t)
Next