event FocusChanged ()
Occurs when a new cell is focused.

TypeDescription

Use the FocusChanged event to notify whether the cell gets the focus. Use the SelectionChanged event to notify your application user changes the selection. Use the FocusColumnIndex property to get to index of the column that has the focus. The FocusItem property indicates the focused item. The SelectColumnInner property indicates the index of an inner cell that has the focus. Use the FullRowSelect property to specify whether the control selects the entire item or a single/multiple cells. Use the SelectItem property to programmatically select an item( it changes the focused items too ). Use the InnerCell property to access an inner cell.

The control fires the FocusChanged event when the user changes:

Syntax for FocusChanged event, /NET version, on:

private void FocusChanged(object sender)
{
}

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

Syntax for FocusChanged event, /COM version, on:

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

void OnFocusChanged()
{
}

void __fastcall FocusChanged(TObject *Sender)
{
}

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

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

begin event FocusChanged()
end event FocusChanged

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

Private Sub FocusChanged()
End Sub

Private Sub FocusChanged()
End Sub

LPARAMETERS nop

PROCEDURE OnFocusChanged(oGrid)
RETURN

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

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

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

Procedure OnComFocusChanged 
	Forward Send OnComFocusChanged 
End_Procedure

METHOD OCX_FocusChanged() CLASS MainDialog
RETURN NIL

void onEvent_FocusChanged()
{
}

function FocusChanged as v ()
end function

function nativeObject_FocusChanged()
return

The following VB sample determines the focused cell:

Private Sub Grid1_FocusChanged()
    With Grid1
        Dim hFocusCell As EXGRIDLibCtl.HCELL
        hFocusCell = .Items.ItemCell(.Items.FocusItem, .FocusColumnIndex)
        Debug.Print "Focus = " & .Items.CellCaption(, hFocusCell) & " (" & hFocusCell & ")"
    End With
End Sub

The following VB sample determines the focused cell, if the control contains inner cells:

Private Sub Grid1_FocusChanged()
    With Grid1
        Dim hFocusCell As EXGRIDLibCtl.HCELL
        hFocusCell = .Items.ItemCell(.Items.FocusItem, .FocusColumnIndex)
        If (.SelectColumnInner > 0) Then
            ' Do we selected an inner cell?
            hFocusCell = .Items.InnerCell(, hFocusCell, .SelectColumnInner)
        End If
        Debug.Print "Focus = " & .Items.CellCaption(, hFocusCell) & " (" & .FocusColumnIndex & "," & .SelectColumnInner & ")"
    End With
End Sub

The following C++ sample displays the focused cell:

#include "Items.h"
void OnFocusChangedGrid1() 
{
	if ( IsWindow( m_grid.m_hWnd ) ) 
	{
		CItems items = m_grid.GetItems();
		COleVariant vtItem( items.GetFocusItem() ), vtColumn( m_grid.GetFocusColumnIndex() );
		CString strFormat;
		strFormat.Format( "Focus on '%s'", V2S( &items.GetCellValue( vtItem, vtColumn ) ) );
		OutputDebugString( strFormat );
	}
}

The following C++ sample displays the focused cell, if the control contains inner cells:

#include "Items.h"
void OnFocusChangedGrid1() 
{
	if ( IsWindow( m_grid.m_hWnd ) ) 
	{
		CItems items = m_grid.GetItems();
		COleVariant vtMissing; V_VT( &vtMissing) = VT_ERROR;
		COleVariant vtFocusCell( items.GetItemCell( items.GetFocusItem(), COleVariant(m_grid.GetFocusColumnIndex())));
		if ( m_grid.GetSelectColumnInner() > 0 )
			vtFocusCell = items.GetInnerCell( vtMissing, vtFocusCell, COleVariant(m_grid.GetSelectColumnInner()));
		CString strFormat;
		strFormat.Format( "Focus on '%s'", V2S( &items.GetCellValue( vtMissing, vtFocusCell ) ) );
		OutputDebugString( strFormat );
	}
}

The following VB.NET sample displays the focused cell:

Private Sub AxGrid1_FocusChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxGrid1.FocusChanged
    With AxGrid1.Items
        Debug.Print("Focus on '" & .CellValue(.FocusItem, AxGrid1.FocusColumnIndex()).ToString() & "'")
    End With
End Sub

The following VB.NET sample displays the focused cell, if the control contains inner cells:

Private Sub AxGrid1_FocusChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxGrid1.FocusChanged
    With AxGrid1.Items
        Dim focusCell As Object = .ItemCell(.FocusItem, AxGrid1.FocusColumnIndex)
        If (AxGrid1.SelectColumnInner > 0) Then
            focusCell = .InnerCell(Nothing, focusCell, AxGrid1.SelectColumnInner)
        End If
        Debug.Print("Focus on '" & .CellValue(Nothing, focusCell).ToString() & "'")
    End With
End Sub

The following C# sample displays the focused cell:

private void axGrid1_FocusChanged(object sender, EventArgs e)
{
	object focusValue = axGrid1.Items.get_CellValue(axGrid1.Items.FocusItem, axGrid1.FocusColumnIndex);
	System.Diagnostics.Debug.WriteLine("Focus on '" + (focusValue != null ? focusValue.ToString() : "" ) + "'");
}

The following C# sample displays the focused cell, if the control contains inner cells:

private void axGrid1_FocusChanged(object sender, EventArgs e)
{
	object focusCell = axGrid1.Items.get_ItemCell(axGrid1.Items.FocusItem, axGrid1.FocusColumnIndex);
	if ( axGrid1.SelectColumnInner > 0 )
		focusCell = axGrid1.Items.get_InnerCell( null, focusCell, axGrid1.SelectColumnInner );
	object focusValue = axGrid1.Items.get_CellValue(null, focusCell);
	System.Diagnostics.Debug.WriteLine("Focus on '" + (focusValue != null ? focusValue.ToString() : "" ) + "'");
}

The following VFP sample displays the focused cell:

*** ActiveX Control Event ***

with thisform.Grid1.Items
	.DefaultItem = .FocusItem
	wait window nowait .CellCaption( 0, thisform.Grid1.FocusColumnIndex() )
endwith