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 » Catch events from CExtGridWnd in a Dialog Collapse All
Subject Author Date
Johannes Wisnewski May 13, 2011 - 6:13 AM

Hallo,

I use a CExtGridWnd Derived grid class in a CDialog. Now I want to catch events from the grid, to work with them in my CDialog Class, something like:

BEGIN_MESSAGE_MAP(CDialog)
    ON_EVENT(CDialog, IDC_PROFUISGRID, GRID_CHANGE, OnGridChange)
END_MESSAGE_MAP()

Does something like that work, and where is the documentation for it?

Thank you for helping,

Johannes

Technical Support May 13, 2011 - 12:38 PM

Because there is a great number of possible grid events, all Prof-UIS grid controls use virtual methods rather than notification messages. Notification messages are slower than virtual methods. You can override virtual methods of a grid control or virtual methods of cell classes. For instance, you can override the CExtGridWnd::OnGridCellInplaceControlTextInputVerify() or CExtGridCell::OnInplaceControlTextInputVerify() virtual methods to track any editing action in a grid cell and filter using input, including the final editing event. You can override CExtGridWnd::OnGridCellInputComplete() virtual method to catch any cell modification event: editing, built-in check box or up-down button events, picking something from the popup control displayed on mouse click over built-in cell’s drop-down button, editing cell using some modal dialog displayed after click on cell’s ellipsis button. Your overriden virtual method can get grid’s parent dialog window and invoke methods of your dialog class.

Johannes Wisnewski May 15, 2011 - 4:27 AM

Ok, but then I have to write a new derivation of my CExtGridWnd Dreived class for every single Dialog. Thats not very practical.

Is it possible, to trigger an event, which I can get with the ON_EVENT in the message map of my parent Dialog? For example in the override of my OnGridCellInputComplete() function, so I could catch this event in every parent dialog, no matter what class the parent dialog is.

And if this does not work: How can I get the parents dialog into my OnGridCellInputComplete Function? With GetParent?

Thank you,

Johannes

Technical Support May 16, 2011 - 11:43 AM

First of all, your dialog class should have at least DECLARE_DYNAMIC/IMPLEMENT_DYNAMIC in its declaration/implementation. This will allow you to use DYNAMIC_DOWNCAST/STATIC_DOWNCAST in grid’s code:

void CYourGrid::OnGridCellInputComplete(
    CExtGridCell & _cell,
    LONG nColNo,
    LONG nRowNo,
    INT nColType,
    INT nRowType,
    HWND hWndInputControl // = NULL
    )
{
    ASSERT_VALID( this );
    __super::OnGridCellInputComplete( _cell, nColNo, nRowNo, nColType, nRowType, hWndInputControl );
CWnd * pWndParent = GetParent();
CYourDialog * pYourDialog = DYNAMIC_DOWNCAST( CYourDialog, pWndParent );
    if( pYourDialog != NULL )
        pYourDialog->SomeMethod( . . . );
}

If you don’t like this approach, then you can use interfaces. First of all, you will need to declare interface with events you need. For instance:
interface IMyGridEvents
{
    virtual void MyGridEvents_OnGridCellInputComplete(
        CExtGridWnd & wndGrid,
        CExtGridCell & _cell,
        LONG nColNo,
        LONG nRowNo,
        INT nColType,
        INT nRowType,
        HWND hWndInputControl = NULL
        ) = 0;
};

Then you will need to learn your grid control to use your interface. So, the grid class should look like:
class CYourGrid : public CExtGridWnd
{
public:
    IMyGridEvents * m_pMyGridEvents;
    CYourGrid()
        : m_pMyGridEvents( NULL )
    {
    }
    virtual void OnGridCellInputComplete(
        CExtGridCell & _cell,
        LONG nColNo,
        LONG nRowNo,
        INT nColType,
        INT nRowType,
        HWND hWndInputControl = NULL
        )
    {
        ASSERT_VALID( this );
        __super::OnGridCellInputComplete( _cell, nColNo, nRowNo, nColType, nRowType, hWndInputControl );
        if( m_pMyGridEvents != NULL )
            m_pMyGridEvents->MyGridEvents_OnGridCellInputComplete( *this, _cell, nColNo, nRowNo, nColType, nRowType, hWndInputControl );
    }
};

Now you can use this grid class in your dialog class. But you should learn the dialog to receive grid events through the interface. So, the dialog class should look like:
class CYourDialog : public CExtNCW < CExtResizableDialog >, public IMyGridEvents
{
public:
    CYourGrid m_grid;
    CYourDialog()
    {
        m_grid->m_pMyGridEvents = this;
    }
    virtual void MyGridEvents_OnGridCellInputComplete(
        CExtGridWnd & wndGrid,
        CExtGridCell & _cell,
        LONG nColNo,
        LONG nRowNo,
        INT nColType,
        INT nRowType,
        HWND hWndInputControl = NULL
        )
    {
        ASSERT_VALID( this );
    }
};

We have the wndGrid parameter in the interface method. This allows us to use it for receiving events from more than one grid control.