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.
Subject |
Author |
Date |
|
Sebastian Leopold
|
Apr 20, 2008 - 6:26 AM
|
Hello, I dont understand how to work with the "CExtGridWnd" class. I understand how to add Columns and fill it with Data but, how can I get any events from the Grid. Are there any window messages wich are thrown ?? or do I have to derive a class from CExtGridWnd and override some virtual methods to get the events. How can I get a event when a cell get selected ? I need that because I want to update some Controls on grid selection ? Regards S.Leopold
|
|
Technical Support
|
Apr 22, 2008 - 8:52 AM
|
|
|
D. Cameron DeHeer
|
Apr 22, 2008 - 7:42 AM
|
Hi Sebastian, I ran into the same issue and ended up subclassing the grid control as CGridWnd and overloading OnGbwSelectionChanged and OnGridCellInputComplete to post user-defined messages to the parent window. Some other overrides would be nice for item inserts, deletes, etc. as well, but I haven’t added them yet. Code snippets for these is below, the GN_SELECTIONCHANGED and GN_CELLINPUTCOMPLETE are #defined as offsets from WM_USER. I would be interested to hear someone from Prof-UIS or other users to give their insight on this, however, because in general I think it would be nice if this was supported out of the box. Hope this helps. Regards, Cameron void CGridWnd::OnGbwSelectionChanged()
{
GetParent()->PostMessage(WM_COMMAND,
MAKEWPARAM(GetDlgCtrlID(), GN_SELECTIONCHANGED),
(LPARAM)m_hWnd); CExtGridWnd::OnGbwSelectionChanged();
} void CGridWnd::OnGridCellInputComplete(CExtGridCell &_cell,
LONG nColNo,
LONG nRowNo,
INT nColType,
INT nRowType,
HWND hWndInputControl)
{
GetParent()->PostMessage(WM_COMMAND,
MAKEWPARAM(GetDlgCtrlID(), GN_CELLINPUTCOMPLETE),
(LPARAM)m_hWnd); CExtGridWnd::OnGridCellInputComplete(_cell,
nColNo,
nRowNo,
nColType,
nRowType,
hWndInputControl);
}
|
|
Technical Support
|
Apr 24, 2008 - 7:23 AM
|
Of course, with some additional efforts you can implement any notification algorithm and your solution is suitable. We already helped some of our users to make the grid events compatible with its existing handler for the NM_CLICK notification. In this we can generate this notification ourselves as follows: void CMyGridWnd::OnGbwFocusChanged(
const POINT & ptOldFocus,
const POINT & ptNewFocus
)
{
ASSERT_VALID( this );
CWnd * pWndOwner = GetOwner();
if( pWndOwner->GetSafeHwnd() == NULL
|| (!::IsWindow( pWndOwner->m_hWnd ))
)
return;
ASSERT_VALID( pWndOwner );
CPoint ptCursor( 0, 0 );
::GetCursorPos( &ptCursor );
NMCLICK nmclick;
nmclick.hdr.code = NM_CLICK;
nmclick.hdr.idFrom = GetDlgCtrlID();
nmclick.hdr.hwndFrom = GetSafeHwnd();
nmclick.pt = ptCursor;
pWndOwner->SendMessage(
WM_NOTIFY,
nmclick.hdr.idFrom,
(LPARAM) (NMHDR*) &nmclick
);
} Then add the following line to the message map ON_NOTIFY(NM_CLICK, IDC_MY_GRID, OnClickList1) So the existing OnClickList1() handler will be invoked automatically: void CTest_simple_gridDlg::OnClickList1( NMHDR * pNMHDR, LRESULT * pResult )
{
CPoint ptFocus = m_wndGrid.FocusGet();
CString sLog;
sLog.Format(
_T("FOCUSED ITEM: row: %d, column: %d"),
ptFocus.y, ptFocus.x
);
m_wndLabelLog.SetWindowText( sLog );
*pResult = 0;
} If you have handled some other notification messages, you can generate them in the same way. You can also declare a custom message and send it from grid’s overridden methods to the parent dialog. Here is the sample where this code is used.
|
|