Professional User Interface Suite, Copyright FOSS Software Inc. Help Published with Permission.

There is no need to create a button control and attach it to the grid cell. Actually, you only need to modify the cell style so that you can see one or more buttons in the right part of the cell. The following built-in buttons are supported:

Cell Style Button Type

__EGCS_BUTTON_UPDOWN

Up-down (also known as a spin box)

__EGCS_BUTTON_DROPDOWN

Drop-down

__EGCS_BUTTON_ELLIPSIS

Ellipsis

There are two ways you can handle clicks on a cell button: at the grid window level and at the cell level. The first allows you to put the handler code in one place: use a CExtGridWnd-derived class, override its OnGridCellButtonPressed() method and return true if the click is handled. The method OnGridCellButtonPressed() takes 10 parameters, which provide all the information about the cell and the button:

virtual bool OnGridCellButtonPressed(
CExtGridCell & _cell,
INT nButtonType,
const RECT & rcCellExtra,
const RECT & rcCell,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType
);

The nButtonType parameter specifies the button type and, if it is a up-down button, allows you to determine which part was pressed:

Button Type/Part Enumeration Constant

CExtGridCell::__EBTT_UPDOWN_UP

Upper part of the up-down button

CExtGridCell::__EBTT_UPDOWN_DOWN

Lower part of the up-down button

CExtGridCell::__EBTT_DROPDOWN

Drop-down

CExtGridCell::__EBTT_ELLIPSIS

Ellipsis

The second way of handling button clicks is overriding the OnButtonPressed() method in a CExtGridCell-derived class:

virtual void OnButtonPressed(
CExtGridWnd & wndGrid,
INT nButtonType,
const RECT & rcCellExtra,
const RECT & rcCell,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType
);

For example, for a CExtGridCellString-derived class, the code may look like as follows:

// DECLARATION
class CYourGridCellString : public CExtGridCellString
{
public:

. . .
virtual void OnButtonPressed(
CExtGridWnd & wndGrid,
INT nButtonType,
const RECT & rcCellExtra,
const RECT & rcCell,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType
);

}; // class CYourGridCellString


// IMPLEMENTATION:

void CYourGridCellString::OnButtonPressed(
CExtGridWnd & wndGrid,
INT nButtonType,
const RECT & rcCellExtra,
const RECT & rcCell,
LONG nVisibleColNo,
LONG nVisibleRowNo,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType
)
{
ASSERT_VALID( this );
ASSERT_VALID( (&wndGrid) );

CExtGridCellString::OnButtonPressed(
wndGrid,
nButtonType,
rcCellExtra,
rcCell,
nVisibleColNo,
nVisibleRowNo,
nColNo,
nRowNo,
nColType,
nRowType
);

if( nButtonType == __EBTT_ELLIPSIS )
{
AfxMessageBox( _T("CYourGridCellString::OnButtonPressed") );
}
}

The second approach is more flexible because allows you to enable and disable a cell button by overriding the CExtGridCell::OnQueryButtonInfo() method:

virtual bool OnQueryButtonInfo(
INT nButtonType,
bool * p_bEnabled,
bool * p_bPressed = NULL,
bool * p_bStayPressed = NULL,
UINT * p_nTimerElapseValue = NULL
) const;

A CExtGridCell-derived class can also be used for handling clicks on the up and down parts of the spin button and updating their state independently from each other. The following methods allows you to do this:

virtual bool OnQueryEnabledIncrement() const;
virtual bool OnQueryEnabledDecrement() const;
virtual bool OnValueIncrement();
virtual bool OnValueDecrement();