event ButtonClick (Item as HITEM, ColIndex as Long, Key as Variant)
Occurs when user clicks on the cell's button.

 TypeDescription 
   Item as HITEM A long expression that determines the item's handle. If the Item parameter is 0, and the ColIndex property is different than zero, the ColIndex indicates the handle of the cell where the state is changed.  
   ColIndex as Long A long expression that indicates the column's index, if the Item parameter is not zero, a long expression that indicates the handle of the cell if the Item parameter is 0.  
   Key as Variant Specifies the button's key that's clicked. If the Key parameter is empty, the user clicked the drop down button of the editor.  

Use the ButtonClick event to notify your application that a button is clicked. Use the ColumnClick event to notify your application that the user clicks the column's header. Use the CellImageClick event to notify your application that the user clicks an icon in the cell. You can assign a button to a cell using any of the following ways:

The following VB sample displays the key of the button being clicked:

With G2antt1.Columns.Add("Editor").Editor
    .EditType = EditType
    .AddButton "Key1", 1
    .AddButton "Key2", 2, EXG2ANTTLibCtl.AlignmentEnum.RightAlignment, "This is a bit of text that should be displayed when the cursor is over the button", "Some information"
    .AddButton "Key3", 3, EXG2ANTTLibCtl.AlignmentEnum.RightAlignment
End With
...
Private Sub G2antt1_ButtonClick(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal ColIndex As Long, ByVal Key As Variant)
    ' Displays the button's key that was clicked
    Dim mes As String
    mes = "You have pressed the button"
    mes = mes + IIf(Len(Key) = 0, "", " '" & Key & "'")
    mes = mes + " of cell '" & G2antt1.Items.CellValue(Item) & "'."
    Debug.Print mes
End Sub

The following VB sample displays the caption of the cell where a button is clicked:

Private Sub G2antt1_ButtonClick(ByVal Item As EXG2ANTTLibCtl.HITEM, ByVal ColIndex As Long, ByVal Key As Variant)
    With G2antt1.Items
        Debug.Print .CellValue(Item, ColIndex) & ", Key = '" & Key & "'"
    End With
End Sub

The following C++ sample displays the caption of the cell where a button is clicked:

#include "Items.h"
void OnButtonClickG2antt1(long Item, long ColIndex, const VARIANT FAR& Key) 
{
	CItems items = m_g2antt.GetItems();
	CString strFormat;
	strFormat.Format( "%s, Key = '%s'", items.GetCellValue( COleVariant( Item ), COleVariant( ColIndex ) ), V2S( (LPVARIANT)&Key ) );
	OutputDebugString( strFormat );
}

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;
}

if you are using STL.

The following VB.NET sample displays the caption of the cell where a button is clicked:

Private Sub AxG2antt1_ButtonClick(ByVal sender As Object, ByVal e As AxEXG2ANTTLib._IG2anttEvents_ButtonClickEvent) Handles AxG2antt1.ButtonClick
    With AxG2antt1.Items
        Dim strKey As String = ""
        If Not (e.key Is Nothing) Then
            strKey = e.key.ToString()
        End If
        Debug.Print(.CellValue(e.item, e.colIndex).ToString() + ", Key = " + strKey)
    End With
End Sub

The following C# sample displays the caption of the cell where a button is clicked:

private void axG2antt1_ButtonClick(object sender, AxEXG2ANTTLib._IG2anttEvents_ButtonClickEvent e)
{
	string strKey = "";
	if (e.key != null)
		strKey = e.key.ToString();
	System.Diagnostics.Debug.WriteLine(axG2antt1.Items.get_CellValue(e.item, e.colIndex) + ", Key = " + strKey);
}

The following VFP sample displays the caption of the cell where a button is clicked:

*** ActiveX Control Event ***
LPARAMETERS item, colindex, key

with thisform.G2antt1.Items
	.DefaultItem = item
	wait window nowait .CellValue(0, colindex)
endwith

 


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