Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » CExtReportGridWnd - handling OnButtonPressed Collapse All
Subject Author Date
Cyndi Chatman Mar 9, 2007 - 10:34 AM

I have a column with a combo box that also has an ellipses button. I have created a class that handles the OnButtonPressed handler defined as follows.

In the header file:

class CMyExtGridCellComboBox : public CExtGridCellComboBox
{
    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
        );
};

In the .cpp file:

void CMyExtGridCellComboBox::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 );
    if( nButtonType == __EBTT_ELLIPSIS )
    {
        CExtSafeString strMessage, strCellText;
        TextGet( strCellText );
        strMessage.Format(
            _T("The \"ellipsis\" button has been clicked on cell (%ld,%ld)\n\n")
            _T("Current cell text is \"%s\"\n\n")
            ,
            nColNo,
            nRowNo,
            strCellText.IsEmpty() ? _T("") : LPCTSTR(strCellText)
            );
    
        ::AfxMessageBox( LPCTSTR(strMessage), MB_OK|MB_ICONINFORMATION );
        return;
    } // if( nButtonType == __EBTT_ELLIPSIS )
    CExtGridCellComboBox::OnButtonPressed(
        wndGrid,
        nButtonType,
        rcCellExtra,
        rcCell,
        nVisibleColNo,
        nVisibleRowNo,
        nColNo,
        nRowNo,
        nColType,
        nRowType
        );
}

When populating the grid column, I do the following

CExtGridCell * pCell = NULL;
pCell = ReportItemGetCell( pRGC, pRGI, RUNTIME_CLASS(CMyExtGridCellComboBox) );
((CMyExtGridCellComboBox*)pCel)->AddString("1");
pCell->TextSet("1");
pCell->ModifyStyle(__EGCS_BUTTON_ELLIPSIS);

I have a break point in my OnButtonPressed handler, but for some reason, the function is not being called when I left click on the ellipsis?

Cyndi Chatman Mar 22, 2007 - 11:35 AM

I have one cell that is a combo box that I have overridden the OnButtonPressed() handler. This one is working fine.

The problem is a second cell that is not a combo box, but is jsut a string (specifically casted as a CExtGridCellStringDM). If it is not a combo box, but a string, the OnButtonPressed() handler does not work, so I used OnClick()? But... with OnClick() it is only being called once with a nRepCnt of 1?

I made this change after reading the following from the OnButtonPressed on CExtGridCell thread:

"Thank you for the good question. If a grid cell has the __EGCS_NO_INPLACE_CONTROL cell style with no __EGCS_READ_ONLY applied, a single click is interpreted as a click on the drop-down cell button if the __EGCS_BUTTON_DROPDOWN cell style is specified or as a click on the ellipsis cell button if the __EGCS_BUTTON_ELLIPSIS cell style is specified. The drop-down button has a higher priority. This behavior is convenient in most of cases, especially for grid cells inside the property grid control. You can change this behavior by overriding the CExtGridCell::OnClick() virtual method and analyzing the htInfo parameter which describes the click related hit-testing information. If the htInfo.m_nButtonType property is not equal to the INT(CExtGridCell::__EBTT_ELLIPSIS) value, then your OnClick() method should return true. Your OnClick() method should invoke the parent class method and return the returned value otherwise. "

Technical Support Mar 23, 2007 - 2:22 PM

It seems you have a CExtGridCellStringDM cell and you need to catch the event when the user clicks the ellipsis button. If yes, the CDemoComboCell::OnButtonPressed method from the SimpleGrids sample shows how you should do this.

Cyndi Chatman Mar 21, 2007 - 11:32 AM

Sorry, you are correct. I changed to check for nRepCnt instead of nFlags. However, my problem is still that my OnClick() handler is only being invoked once (with a nRepCnt of 1)?

Cyndi Chatman Mar 21, 2007 - 6:55 AM

For some reason, my OnClick() method is only being invoked one time, with nFlags set to 1? Here is the code for my handler:


bool CMyExtGridCellStringDM::OnClick(
     CExtGridWnd & wndGrid,
     const CExtGridHitTestInfo & htInfo,
     UINT nChar,
     UINT nRepCnt,
     UINT nFlags
    )
{
    ASSERT_VALID( this );
    if( htInfo.m_nButtonType != __EBTT_ELLIPSIS )
        return true;

    if (nFlags == 3)
    {
     // do some stuff            
    }
    
    bool ret = CExtGridCellStringDM::OnClick(wndGrid,htInfo,nChar,nRepCnt,nFlags);
    return ret;
}

Any ideas?

Technical Support Mar 22, 2007 - 9:48 AM

In the SimpleGrids sample (the Products page) there is a Quantity Per Unit column with combo box cells that have an ellipsis button. These cells are implemented in the CDemoComboCell class. The CDemoComboCell::OnButtonPressed() method shows how to handle the ellipsis button click.

Suhai Gyorgy Mar 21, 2007 - 9:25 AM

You have to check nRepCnt, not nFlags.

Cyndi Chatman Mar 16, 2007 - 8:32 AM

Never mind. I figured this one out. I had to enable the NO_INPLACE_CONTROL only (no READ_ONLY) and override the OnClick handler instead of the OnButtonPressed handler. However, I have a new issue. If the user clicks the ellipses button, I want to change the format of the grid. If I do this in my OnClick handler, the program crashes when it returns and calls the parent class OnClick because the properties of the cell have been destroyed and redrawn.

Is there an event handler that I can override after a button has been pressed?? Something like OnPostClick()??

Technical Support Mar 16, 2007 - 10:52 AM

The CExtGridCell::OnClick() virtual method is invoked several times with different values in the nRepCnt parameter. You should re-organize the grid content when the nRepCnt parameter is 3. This is assumed as post click event for such actions as in-place editor activation.

Cyndi Chatman Mar 15, 2007 - 4:30 PM

I want to have a column that is read-only, but has an ellipis button in it. I don’t want the user to be able to edit the data directly, but has to click the ellipses. I have created a CMyExtGridCellStringDM class the handles the OnButtonPressed() function, but, if I set the cell to read only and no inplace control by the following:

pCell->ModifyStyle( __EGCS_READ_ONLY );
pCelll->ModifyStyle(__EGCS_NO_INPLACE_CONTROL );

The button becomes disabled as well. Is there a way to have read-only data, and the button still works?

Technical Support Mar 16, 2007 - 10:43 AM

Please use __EGCS_NO_INPLACE_CONTROL only.

Cyndi Chatman Mar 9, 2007 - 11:19 AM

Thanks! I also had to add the following constructor to get rid of casting errors to compile

CMyExtGridCellComboBox::CMyExtGridCellComboBox(
    CExtGridDataProvider * pDP // = NULL
    )
    : CExtGridCellComboBox( pDP )
{
}

Technical Support Mar 9, 2007 - 10:50 AM

Please update your grid cell class declaration and implementation with the run-time type information providers.

In the .h file:

class CMyExtGridCellComboBox : public CExtGridCellComboBox
{
public:
      DECLARE_SERIAL( CMyExtGridCellComboBox );
      IMPLEMENT_ExtGridCell_Clone( CMyExtGridCellComboBox, CExtGridCellComboBox );
      . . .



In the .cpp file:
     . . .
      IMPLEMENT_SERIAL( CMyExtGridCellComboBox , CExtGridCellComboBox, VERSIONABLE_SCHEMA|1 );
      . . .
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
      . . .
Please note, it is very important to put the IMPLEMENT_SERIAL( . . . ) line of code to the top of the .cpp file before the declaration of the MFC’s debug version of the C++ new operator.