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 Tech Support » Length restriction in CExtGridCellString Collapse All
Subject Author Date
Gevork Odabashyan Nov 15, 2006 - 3:48 AM

Hello!

I’m trying to use your grid classes. Suppose we have an object of type CExtPropertyGridCtrl and a CExtGridCellString cell in it. How can I restrict
the number of characters a user can type in it?

Technical Support Nov 16, 2006 - 5:40 AM

It seems you need to invoke the CEdit::SetLimitText() method for the cell inplace edit. You can do this by overriding the OnInplaceControlCreate() virtual method in your cell class:

HWND CMyGridCell::OnInplaceControlCreate(
    CExtGridWnd & wndGrid,
    LONG nVisibleColNo,
    LONG nVisibleRowNo,
    LONG nColNo,
    LONG nRowNo,
    INT nColType,
    INT nRowType,
    const RECT & rcCellExtra,
    const RECT & rcCell,
    const RECT & rcInplaceControl,
    LONG nLastEditedColNo,
    LONG nLastEditedRowNo
    )
{
            ASSERT_VALID( this );
            ASSERT_VALID( (&wndGrid) );
DWORD dwCellStyle = GetStyle();
            if( (dwCellStyle&__EGCS_NO_INPLACE_CONTROL) != 0 )
                        return NULL;
HWND hWndOuter =
                        wndGrid.OnGridCellInplaceControlCreate(
                                    *this,
                                    nVisibleColNo,
                                    nVisibleRowNo,
                                    nColNo,
                                    nRowNo,
                                    nColType,
                                    nRowType,
                                    rcCellExtra,
                                    rcCell,
                                    rcInplaceControl,
                                    nLastEditedColNo,
                                    nLastEditedRowNo
                                    );
            if( hWndOuter != NULL )
                        return hWndOuter;
CExtGridInplaceEdit * pEdit = NULL;
            try
            {
                        pEdit =
                                    new CExtGridInplaceEdit(
                                                wndGrid,
                                                *this,
                                                nVisibleColNo,
                                                nVisibleRowNo,
                                                nColNo,
                                                nRowNo,
                                                nColType,
                                                nRowType,
                                                rcCellExtra,
                                                rcCell,
                                                rcInplaceControl,
                                                nLastEditedColNo,
                                                nLastEditedRowNo
                                                );
                        ASSERT_VALID( pEdit );
                        if( ! pEdit->Create() )
                        {
                                    ASSERT( FALSE );
                                    return NULL;
                        } // if( ! pEdit->Create() )
            } // try
            catch( CException * pXept )
            {
                        ASSERT( FALSE );
                        pXept->Delete();
                        return NULL;
            } // catch( CException * pXept )
            catch( ... )
            {
                        ASSERT( FALSE );
                        return NULL;
            } // catch( ... )
            ASSERT_VALID( pEdit );

pEdit-> SetLimitText( ... );

HWND hWnd = pEdit->GetSafeHwnd();
            ASSERT( hWnd != NULL && ::IsWindow(hWnd) );
            return hWnd;
}