Professional UI Solutions
Site Map   /  Register


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 » Grid Control.... Getting Current row/column and event once data is changed Collapse All
Subject Author Date
Douglas Hoppes Jul 18, 2007 - 5:06 AM

Hi all,

Okay... this is a pretty simple question. I just implemented the grid control on my dialog form and was able to display/retrieve the data properly using the GridCellGet() method. However, I’ve checked the access methods and can’t seem to find out the answer to these two questions:

1) How do I get the current row/column that the user is editing?
2) When a user tabs off of the cell to another cell, how do I get the change? Is there an event that is sent when the cell loses focus?
3) I can’t seem to get the tab to switch between the cells. Is there a Setting for this?


Technical Support Jul 18, 2007 - 10:48 AM

The CExtGridWnd::RowAdd() method adds new row(s) to the bottom. The CExtGridWnd::RowCountGet() method returns the number of rows. You know how many rows you added and you know the number of rows after adding new rows. That is enough to compute the index (indices) of newly added row(s).

Suhai Gyorgy Jul 18, 2007 - 6:40 AM

You can achieve solution for 1) and 2) by deriving a new class from the grid control and overriding some of its methods. Then you should use this new class for your application instead of CExtGridWnd.

You can check all available overridable methods in Prof-UIS Help provided with the library (it’s a .chm file) Just open the Reference->Classes->CExtGridBaseWnd or CExtGridWnd directories in the Help and check the list of Overridables.

1) By overriding either OnGbwBeginEdit or OnGridCellInplaceControlCreate, you can find out when the user starts editing. In both cases you should first call the parent class method and check the return value. With OnGbwBeginEdit, if the return value is false, you should return with false as well. With OnGridCellInplaceControlCreate, if it returns NULL, you should return with NULL as well. These are the cases when the editing cannot start for some reason. Otherwise, nColNo and nRowNo parameters tell you the current row and column, you can use them for your specific needs.

2) From your previous question, I’m not sure if you really want the "focus-changed" event or the "editing-complete" event.
First can be achieved by overriding OnGbwFocusChanged method.
Second can be achieved by overriding OnGridCellInputComplete method.

3) As much as I know, there’s no style available for that. Switch between cells can be achieved by up-down-left-right keys.
You can check most available styles again in Help: click on Reference->Classes->CExtGridBaseWnd or Reference->Classes->CExtGridWnd entries.

Douglas Hoppes Jul 18, 2007 - 9:51 AM

Thanks for the reply. I overrode the event, but I don’t seem to be dropping in that event.

Also (as a quick side note).... when I add a row using AddRow(), how can I get the row number of the newly added row?


Suhai Gyorgy Jul 19, 2007 - 1:41 AM

When the overriden method doesn’t seem to be called, I usually check the original method’s syntax in Prof-UIS source code. Help is not always updated to the very latest syntax. In this case you should check the ExtGridWnd.h file in Include directory and search for the name of the method. Be sure to check whether the method has the const modifier.

Technical Support Jul 18, 2007 - 10:42 AM

In addition to what Chris wrote we would like to add the following:

The cell traversing can be easily done. Just create a class derived from CExtGridWnd and override the PreTranslateMessage virtual method like as follows

BOOL CYourGridWnd::PreTranslateMessage( MSG * pMsg )
    if(    pMsg->message == WM_KEYDOWN
        && pMsg->wParam == VK_TAB
        bool bAlt =
          ( (::GetAsyncKeyState(VK_MENU)&0x8000) != 0 )
            ? true : false;
        bool bCtrl =
          ( (::GetAsyncKeyState(VK_CONTROL)&0x8000) != 0 )
            ? true : false;
        bool bShift =
          ( (::GetAsyncKeyState(VK_SHIFT)&0x8000) != 0 )
            ? true : false;
        if( !( bAlt || bCtrl ) )
            LONG nColCount = ColumnCountGet();
            LONG nRowCount = RowCountGet();
            if( nColCount > 1 && nRowCount > 0 )
                CPoint ptFocus = FocusGet();
                if( ptFocus.x >= 0 && ptFocus.y >= 0 )
                    CPoint ptNewFocus = ptFocus;
                    if( bShift )
                        if( ptFocus.x > 0 )
                            ptNewFocus.x --;
                    } // if( bShift )
                        if( ptFocus.x < (nColCount-1) )
                            ptNewFocus.x ++;
                    } // else from if( bShift )
                    if( ptNewFocus != ptFocus )
                        bool bContinueEdit = false;
                        CWnd * pWndFocus =
                        if(    pWndFocus != NULL
                            && pWndFocus->IsKindOf(
                            bContinueEdit = true;
                        SendMessage( WM_CANCELMODE );
                    FocusSet( ptNewFocus );
                    if( bContinueEdit )
                    } // if( ptNewFocus != ptFocus )
                } // if( ptFocus.x >= 0 && ptFocus.y >= 0 )
            } // if( nColCount > 1 && nRowCount > 0 )
        } // if( !( bAlt || bCtrl ) )
        return TRUE;
 return CExtGridWnd::PreTranslateMessage( pMsg );
Now, your grid supports switching between cells in a row with the Tab or Shift+Tab keys.