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 » resize inplace edit of a grid cell Collapse All
Subject Author Date
Ulrich Heinicke Aug 28, 2007 - 7:52 AM

I used in my program a grid (used today the MFSGridCtrl from CodeProject) with normally display values, but when the user start edit the cell the text will be changed to the formula string and after end editing the formula will be calculated and the values displayed. Now i will be changed to CExtGridWnd. I overwrite the function OnGridCellInplaceControlCreate to switch from value to the formula. And overwrite the function OnGridCellInplaceControlTextInputComplete to display the calculated value. The column width is set to 100, that is enough to display the value. But the formula string could be larger. The MFCGridCtrl has a InplaceEdit which resize the edit window automaticly. Is there a possiblity to have the same feature with CExtGridWnd?
Thanks
Ulrich

Ulrich Heinicke Sep 4, 2007 - 1:57 PM

Hi,
i send the both files per email to you.

Ulrich

Technical Support Sep 6, 2007 - 5:53 AM

We replied you by email.

Ulrich Heinicke Sep 4, 2007 - 8:26 AM

Since last week i have the source code, so i patch the file ExtGridWnd.h and ExtGridWnd.cpp to have an edit fields that is larger then the column width and can be grow.
I insert in ExtGridWnd.h in the class CExtGridCell a new member function:
    void    GrowSet( BOOL bValue )
    {
        bGrow = bValue;
    };
and in the class CExtGridInplaceEdit:
    void    GrowSet( BOOL bValue )
    {
        bGrow = bValue;
    };

In the file ExtGridWnd.cpp i modify the function OnInplaceControlCreate with:
    CExtGridInplaceEdit * pEdit = NULL;
    //////////////////////////////////////////////////////////////////////////
    CRect    rcInplaceCtrl = rcInplaceControl;
    if (bGrow)
    {
        CExtSafeString str;
        TextGet( str );
        str += _T(" ");

        CDC * pDC = wndGrid.GetDC();
        CSize size = pDC->GetTextExtent( str );

        // Get client rect
        CRect ParentRect;
        wndGrid.GetParent()->GetClientRect( &ParentRect );

        // Check whether control needs to be resized
        // and whether there is space to grow
        if (size.cx > rcInplaceCtrl.Width())
        {
            if( size.cx + rcInplaceCtrl.left < ParentRect.right )
                rcInplaceCtrl.right = rcInplaceCtrl.left + size.cx;
            else
                rcInplaceCtrl.right = rcInplaceCtrl.right;
        }
    }
    //////////////////////////////////////////////////////////////////////////
    try
    {
        pEdit =
            new CExtGridInplaceEdit(
                wndGrid,
                *this,
                nVisibleColNo,
                nVisibleRowNo,
                nColNo,
                nRowNo,
                nColType,
                nRowType,
                rcCellExtra,
                rcCell,
                //////////////////////////////////////////////////////////////////////////
                rcInplaceCtrl,        // rcInplaceControl,
                //////////////////////////////////////////////////////////////////////////
                nLastEditedColNo,
                nLastEditedRowNo
                );

and in the fuction CExtGridInplaceEdit::WindowProc:
    if(        message == WM_CHAR
......
        if( ! _DoVerifyTextInput(false) )
        {
            SetRedraw( FALSE );

            SetSel( 0, -1, TRUE );
            ReplaceSel( sTextOld );
            SetSel( dwSelSaved, FALSE );

            SetRedraw( TRUE );
            Invalidate();
            UpdateWindow();
        }
        //////////////////////////////////////////////////////////////////////////
        /// Resize edit control if needed

        // Get text extent
        GetWindowText( sTextOld );

        // add some extra buffer
        sTextOld += _T(" ");

        CWindowDC dc( this );
        CFont *pFontDC = dc.SelectObject(GetFont());
        CSize size = dc.GetTextExtent( sTextOld );
        dc.SelectObject( pFontDC );

        // Get client rect
        CRect ParentRect;
        GetParent()->GetClientRect( &ParentRect );

        // Check whether control needs to be resized
        // and whether there is space to grow
        if (size.cx > m_rcInplaceControl.Width())
        {
            if( size.cx + m_rcInplaceControl.left < ParentRect.right )
                m_rcInplaceControl.right = m_rcInplaceControl.left + size.cx;
            else
                m_rcInplaceControl.right = ParentRect.right;
            MoveWindow( &m_Rect );
        }
        //////////////////////////////////////////////////////////////////////////

Maybe it’s not very elegant, but it work. It is possible to have somethings like this into the next version?
Thanks
Ulrich

Technical Support Sep 4, 2007 - 11:48 AM

It is not a problem to add this feature to the grid’s inplace editor and cells. Thank you. Could you send us the ExtGridWnd.h/.cpp files to support@prof-uis.com so that we can compare this with our version and test this?