

| Type | Description | |||
| 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 |
On the bottom of the page you can find samples for using the /NET Assembly or /WPF component. The newer versions of the /NET, WPF version provides the get_SelectedBars and get_SelectedLinks properties that returns a collection of selected bars and links, beside the get_SelectedObjects property that may returns all objects being selected in the Chart area.
In the /COM version 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
NextThe 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 sample removes the selected links only:
With G2antt1
.BeginUpdate
With .Items
For Each l In .SelectedObjects(exSelectLinksOnly)
G2antt1.Template = "Items.RemoveLink(" & l & ")"
Next
End With
.EndUpdate
End With
The following VB sample removes the selected bars only:
With G2antt1
.BeginUpdate
With .Items
For Each b In .SelectedObjects(exSelectBarsOnly)
G2antt1.Template = "Items.RemoveBar(" & b & ")"
Next
End With
.EndUpdate
End With
When a bar is removed, any link related to it will be removed.
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 WithThe 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 ):
exontrol.EXG2ANTTLib.Items items = exg2antt1.Items;
foreach(string bar in items.get_SelectedObjects(exontrol.EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly) as Array)
{
string[] s = bar.Split(new Char[] {','});
System.Diagnostics.Debug.Print(items.get_ItemBar(Int32.Parse(s[0]), s[1].Substring(0, s[1].Length-2), exontrol.EXG2ANTTLib.ItemBarPropertyEnum.exBarName).ToString());
}
The following VB.NET sample displays the name of the bars being selected ( applicable to NET assemblies inserted to NET forms ):
With Exg2antt1.Items
Dim bar As String, s As String()
For Each bar In CType(.get_SelectedObjects(exontrol.EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly), Object())
s = Split(bar, ",")
Debug.Print(.get_ItemBar(CInt(s(0)), Mid(s(1), 2, Len(s(1)) - 2), exontrol.EXG2ANTTLib.ItemBarPropertyEnum.exBarName).ToString())
Next
End With
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)
NextIn the /NET assembly you can use the
Items.get_ItemBar or Items.set_ItemBar to access properties of the bar giving its handle and key.
The key of the bar is contained between " characters so if you are using the ItemBar property make sure that you are removing the " characters from start and end position.
The get_SelectedObjects property retrieves an array of string objects. If the
string starts with the " character it means that it is a link, else it is
a bar. The name of the link is contained between " characters, while the bar
information contains the handle of the item and the key of the bar as (item,"key"),
where the item is the handle of the item, while the key is the key of the bar.
The following C# sample changes the color of the selected bar(s):
private void exg2antt1_ChartSelectionChanged(object sender)
{
foreach (string o in exg2antt1.Items.get_SelectedObjects(exontrol.EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly) as Array)
{
String[] b = o.Split(",".ToCharArray());
exg2antt1.Items.set_BarColor( int.Parse(b[0]), b[1].Substring(1,b[1].Length -2), Color.Red );
}
}
The following C# sample changes the color of the selected link(s):
private void exg2antt1_ChartSelectionChanged(object sender)
{
foreach (string o in exg2antt1.Items.get_SelectedObjects(exontrol.EXG2ANTTLib.SelectObjectsEnum.exSelectLinksOnly) as Array)
{
exg2antt1.Items.set_Link(o.Substring(1, o.Length - 2), exontrol.EXG2ANTTLib.LinkPropertyEnum.exLinkColor, ColorTranslator.ToWin32(Color.Red));
}
}
The following VB.NET sample changes the color of the selected bar(s):
Private Sub Exg2antt1_ChartSelectionChanged(ByVal sender As System.Object) Handles Exg2antt1.ChartSelectionChanged
Dim o As String
For Each o In Exg2antt1.Items.get_SelectedObjects(exontrol.EXG2ANTTLib.SelectObjectsEnum.exSelectBarsOnly)
Dim b As String() = o.Split(",".ToCharArray())
Exg2antt1.Items.set_BarColor(CInt(b(0)), b(1).Substring(1, b(1).Length - 2), Color.Red)
Next
End Sub
The following VB.NET sample changes the color of the selected link(s):
Private Sub Exg2antt1_ChartSelectionChanged(ByVal sender As System.Object) Handles Exg2antt1.ChartSelectionChanged
Dim o As String = ""
For Each o In Exg2antt1.Items.get_SelectedObjects(exontrol.EXG2ANTTLib.SelectObjectsEnum.exSelectLinksOnly)
Exg2antt1.Items.set_Link(o.Substring(1, o.Length - 2), exontrol.EXG2ANTTLib.LinkPropertyEnum.exLinkColor, ColorTranslator.ToWin32(Color.Red))
Next
End SubThe newer versions of the /NET,WPF version provides the get_SelectedBars and get_SelectedLinks properties that returns a collection of selected bars and links.
The following C# sample changes the color of the selected bar(s):
private void exg2antt1_ChartSelectionChanged(object sender)
{
List<exontrol.EXG2ANTTLib.Items.SelectedBar> sBars = exg2antt1.Items.get_SelectedBars();
if (sBars != null)
foreach (exontrol.EXG2ANTTLib.Items.SelectedBar bar in sBars)
exg2antt1.Items.set_BarColor(bar.Item, bar.Key, Color.Red);
}
The following C# sample changes the color of the selected link(s):
private void exg2antt1_ChartSelectionChanged(object sender)
{
List<string> sLinks = exg2antt1.Items.get_SelectedLinks();
if (sLinks != null)
foreach (string link in sLinks)
exg2antt1.Items.set_Link(link, exontrol.EXG2ANTTLib.LinkPropertyEnum.exLinkColor, ColorTranslator.ToWin32(Color.Red));
}
The following VB.NET sample changes the color of the selected bar(s):
Private Sub Exg2antt1_ChartSelectionChanged(ByVal sender As System.Object) Handles Exg2antt1.ChartSelectionChanged
With Exg2antt1
Dim sBars As List(Of exontrol.EXG2ANTTLib.Items.SelectedBar) = .Items.get_SelectedBars()
If Not (sBars Is Nothing) Then
Dim bar As exontrol.EXG2ANTTLib.Items.SelectedBar
For Each bar In sBars
.Items.set_BarColor(bar.Item, bar.Key, Color.Red)
Next
End If
End With
End SubThe following VB.NET sample changes the color of the selected link(s):
Private Sub Exg2antt1_ChartSelectionChanged(ByVal sender As System.Object) Handles Exg2antt1.ChartSelectionChanged
With Exg2antt1
Dim sLinks As List(Of String) = .Items.get_SelectedLinks()
If Not (sLinks Is Nothing) Then
Dim link As String
For Each link In sLinks
.Items.set_Link(link, exontrol.EXG2ANTTLib.LinkPropertyEnum.exLinkColor, ColorTranslator.ToWin32(Color.Red))
Next
End If
End With
End Sub