![]() | Type | Description | ||
| 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 CellHasButton property specifies whether the cell displays a button. Use the CellValue property indicates the button's caption. In this case the Key parameter is empty.
The AddButton method adds a button to an editor. The Key parameter indicates the key of the button being clicked. A drop down type editor like ButtonType, DropDownType, DropDownListType, PickEditType, DateType, ColorType, FontType and PictureType includes a drop down button. The Key parameter is empty, for a drop down button.
The following VB sample displays the key of the button being clicked:
With Grid1.Columns.Add("Editor").Editor
.EditType = EditType
.AddButton "Key1", 1
.AddButton "Key2", 2, EXGRIDLibCtl.AlignmentEnum.RightAlignment, "This is a bit of text that should be displayed when the cursor is over the button", "Some information"
.AddButton "Key3", 3, EXGRIDLibCtl.AlignmentEnum.RightAlignment
End With
...
Private Sub Grid1_ButtonClick(ByVal Item As EXGRIDLibCtl.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 '" & Grid1.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 Grid1_ButtonClick(ByVal Item As EXGRIDLibCtl.HITEM, ByVal ColIndex As Long, ByVal Key As Variant)
With Grid1.Items
Debug.Print .CellCaption(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 OnButtonClickGrid1(long Item, long ColIndex, const VARIANT FAR& Key)
{
CItems items = m_grid.GetItems();
CString strFormat;
strFormat.Format( "%s, Key = '%s'", items.GetCellCaption( 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 AxGrid1_ButtonClick(ByVal sender As Object, ByVal e As AxEXGRIDLib._IGridEvents_ButtonClickEvent) Handles AxGrid1.ButtonClick
With AxGrid1.Items
Dim strKey As String = ""
If Not (e.key Is Nothing) Then
strKey = e.key.ToString()
End If
Debug.Print(.CellCaption(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 axGrid1_ButtonClick(object sender, AxEXGRIDLib._IGridEvents_ButtonClickEvent e)
{
string strKey = "";
if (e.key != null)
strKey = e.key.ToString();
System.Diagnostics.Debug.WriteLine(axGrid1.Items.get_CellCaption(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.Grid1.Items .DefaultItem = item wait window nowait .CellCaption(0, colindex) endwith