property Items.SelectedObjects (Objects as SelectObjectsEnum) as Variant
Retrieves a collection of selected objects in the chart.

 TypeDescription 
   Objects as SelectObjectsEnum A combination of SelectObjectsEnum values that indicates the objects being returned. For instance, the SelectedObject(exSelectBarsOnly) retrieves only selected bars, or SelectedObject(exSelectBarsOnly Or exObjectsJustAdded) retrieves only the bars that were added to the selection since the selection was changed.  
   Variant A Collection of strings, each string indicating the bars or the links, or a String that indicates the first selected bar or link, if the Objects parameter includes the exSelectSingleObject. The bars are returned as HANDLE,"KEY", since the link is returned as "KEY".  Shortly, the SelectedObjects property retrieves a string that indicates the first selected bar or link, if the Objects parameter includes the exSelectSingleObject value, else it returns a collection of strings, that indicates the selected bars or links in the chart  
Use the SelectedObject property to retrieve a collection of selected bars or/and links.  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 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.

Let's say that you want to retrieve the name of the bars, in this case you need to build the s-script "Items.ItemBar(<%BAR%>,0)" where the <%BAR%> should be replaced with the strings in the collection being returned by the SelectedObjects property, and 0 indicates the exBarName. Once you built this string, you just call the ExecuteTemplate property and so the name of the bar is returned for each bar selected as shown in the bellow samples. Instead, if links are returned, and you want to access a property of the link, you need to build the x-script "Items.Link(<%LINK%>,12)"  where it gets the text being assigned to selected links, as 12 indicates the exLinkText.

The following VB sample displays the list of selected bars:

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

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

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

The following VB.NET sample displays the list of selected bars ( applicable to COM inserted to NET forms ):

	Dim c As String
	For Each c In AxG2antt1.Items.SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly)
	   Debug.Print(c)
	Next

The following VB.NET sample displays the name of the bars being selected ( applicable to COM inserted to NET forms ):

    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

The following C# sample displays the list of selected bars ( applicable to COM inserted to NET forms ):

    foreach (string c in axG2antt1.Items.get_SelectedObjects(EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly) as Array ) 
    {
        System.Diagnostics.Debug.WriteLine( c );
    }

The following C# sample displays the name of the bars being selected ( applicable to NET assemblies inserted to NET forms ):

    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"
{
	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 the name of the bars being selected:

#include "Items.h"
{
	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:

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

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

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
 


Send comments on this topic.
© 1999-2008 Exontrol Inc, Software. All rights reserved.