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 » About CExtGridCellCheckBox Collapse All
Subject Author Date
VALGOR Jul 7, 2009 - 12:42 PM

Dear team suport

I have with CExtGridCell .... I put in a CExtGridWnd with a cell type CExtGridCellCheckBox....
clicking on that cell changes perfectly "on" a "off" and places a text "Sí" and "No"

But my problem is when I press a button to read the value of that cell by means of a CExtButton always puts the same value in my case

INT MyGrid->GetCheck() = 1.

void CMyDlg::OnBnClickedButton1()
{
// Position cell to load ( but worth every position )
int xx = 1;
int yy = 1;

CExtSafeString aa = "";

CExtGridCellCheckBox *pDataCellC = STATIC_DOWNCAST( CExtGridCellCheckBox, m_wndGrid.GridCellGet( xx, yy, 0, 0, RUNTIME_CLASS( ExtGridCellCheckBox ) ) );
if( pDataCellC )
{
     ASSERT_VALID( pDataCellC );

     aa = "false";
     if( pDataCellC->GetCheck() ) <-------------- Always = 1 Why????
        aa = "true";

     AfxMessageBox( aa );
}
}


Is there a way to read the cell value correctly outside the CExtGridWnd?

Thank you..

VALGOR Jul 9, 2009 - 7:27 PM

Thank you very much for your help.

VALGOR Jul 8, 2009 - 4:54 PM

Sorry I forgot to put the I initialized of cell type   CExtGridCellCheckBox 

to read its value


pS_DatoC->ModifyStyle(

__EGCS_CHK_CHECK // tiene checkbox

|__EGCS_CHECKED // marca del check a on

|__EGCS_ICA_HORZ_CENTER // horizontal centro

|__EGCS_ICA_VERT_CENTER // vertical medio

);

pS_DatoC->ModifyStyle( __EGCS_NO_INPLACE_CONTROL );

pS_DatoC->SetAutoTextMode( true );


I initialized both to read and to use the same inicialize


 


 


 

Technical Support Jul 8, 2009 - 10:30 AM

We suspect there is something wrong with the check box initialization code. Please show us the complete initialization code of the grid control including filling with grid cells.

VALGOR Jul 8, 2009 - 3:18 PM

// Fill List values cell

void CMyGridSQL::RellenaLista( CSQLResult& res )
{
SQLValueArray arrValues;
CString strItemText = "", temp = "";
long lValor = 0L;

CExtGridCellString *pS_DatoS = NULL;
CExtGridCellVariant *pS_DatoV = NULL;
CExtGridCellCheckBox *pS_DatoC = NULL;

long nFila = 0;
while( res.Fetch( arrValues, false ) )
{
        if( !primera )
     {
         RowInsert( -1L );

             CExtGridCell *pCellHdr = NULL;
              pCellHdr = GridCellGetOuterAtLeft( 0L, nFila, RUNTIME_CLASS( CExtGridCellHeader ) );
             if( pCellHdr != NULL )
             {
             ASSERT_VALID( pCellHdr );
                pCellHdr->ModifyStyle( __EGCS_HDR_FOCUS_ARROW_DISPLAY |__EGCS_HDR_FOCUS_ARROW_RESERVE_SPACE | __EGCS_HDR_ROW_COLUMN_NUMBER | __EGCS_TA_HORZ_RIGHT );
             }
        }

const int nSize = arrValues.GetSize() + 1;
for(int nIndex = 0; nIndex < nSize; nIndex++)
{
            if( DatosCabecera[ nIndex ].m_TipoCampo == ’L’ )
            {
                pS_DatoV = STATIC_DOWNCAST( CExtGridCellVariant, GridCellGet( nIndex, nFila, 0, 0, RUNTIME_CLASS(CExtGridCellVariant) ) );
                if( pS_DatoV != NULL )
                {
                    ASSERT_VALID( pS_DatoV );
                    pS_DatoV->ModifyStyle( DatosCabecera[ nIndex ].m_Align, 0 );

                    const CSQLValue& value = arrValues.ElementAt(nIndex);
                    pS_DatoV->_VariantAssign( (long)value, VT_I4 );
                }
            }

            if( DatosCabecera[ nIndex ].m_TipoCampo == ’S’ || DatosCabecera[ nIndex ].m_TipoCampo == ’F’ )            
            {
                pS_DatoS = STATIC_DOWNCAST( CExtGridCellString, GridCellGet( nIndex, nFila, 0, 0, RUNTIME_CLASS(CExtGridCellString) ) );
                if( pS_DatoS != NULL )
                {
                    ASSERT_VALID( pS_DatoS );
                    pS_DatoS->ModifyStyle( DatosCabecera[ nIndex ].m_Align, 0 );

                    const CSQLValue& value = arrValues.ElementAt(nIndex);
                    strItemText = (LPCTSTR)value;
                    pS_DatoS->TextSet( strItemText );
                }
            }
            
/////////////////////////////
// Use CExtGridCellCheckBox             
/////////////////////////////

            if( DatosCabecera[ nIndex ].m_TipoCampo == ’E’ )
            {
                pS_DatoC = STATIC_DOWNCAST( CExtGridCellCheckBox, GridCellGet( nIndex, nFila, 0, 0, RUNTIME_CLASS( CExtGridCellCheckBox ) ) );
                if( pS_DatoC != NULL )
                {
                    ASSERT_VALID( pS_DatoC );

                    pS_DatoC->ModifyStyle( __EGCS_NO_INPLACE_CONTROL );
                    pS_DatoC->SetAutoTextMode( true );
                    pS_DatoC->Set3StateMode( false );
                    pS_DatoC->LabelTextSet( 0, _T(" ") );
                    pS_DatoC->LabelTextSet( 1, _T("Sí") );
                    pS_DatoC->SetCheck( 0 );
                }
            }
            
/////////////////////////////
// CExtGridCellCheckBox             
/////////////////////////////            
     }

     nFila++;
}

if( pS_DatoC )
     pS_DatoC = NULL;

if( pS_DatoV )
     pS_DatoV = NULL;

if( pS_DatoS )
     pS_DatoS = NULL;
}

// Load Values cell

void CProveedoresForm::OnItemBorMarcados()
{
    ASSERT_VALID( this );

    CExtGridCellVariant *pS_DatoV = NULL;
    CExtGridCellCheckBox *pS_DatoC = NULL;

    if( ::ProfUISMsgBox( GetSafeHwnd(), _T("¿Desea borrar los registros marcados?."), _T("*** AVISO ***"), _AVISO | MB_YESNO ) != IDYES )
        return;

    CExtSafeString sqlStr = "";
    CExtSafeString aa = "";

    for( register long nFila = 0; nFila < m_wndGrid->GetTotalFilasINT(); nFila++ )
    {
        pS_DatoV = STATIC_DOWNCAST( CExtGridCellVariant, m_wndGrid->GridCellGet( 0, nFila, 0, 0, RUNTIME_CLASS(CExtGridCellVariant) ) );
        if( pS_DatoV != NULL )
        {
            ASSERT_VALID( pS_DatoV );

            pS_DatoC = STATIC_DOWNCAST( CExtGridCellCheckBox, m_wndGrid->GridCellGet( 10, nFila, 0, 0, RUNTIME_CLASS( CExtGridCellCheckBox ) ) );
                
            if( pS_DatoC != NULL )
            {
                ASSERT_VALID( pS_DatoC );

                pS_DatoC->_Initialize();
                pS_DatoC->SetAutoTextMode( true );

// Try to read the value                
                int ss = pS_DatoC->GetCheck();
                pS_DatoC->TextGet( aa );
                AfxMessageBox( aa );

                bool bMeIsChecked = ( (dwCellStyle & __EGCS_CHECKED) != 0 ) ? true : false; <--------- Always TRUE
                if( bMeIsChecked )
                {
                    sqlStr.Format( _T("%s %d DELETE FROM %s WHERE Empresa = %s AND Codigo = %ld"), aa, ss, ficheroMySQL, App->m_EmpresaActiva, pS_DatoV->lVal );
//                    m_wndGrid->DoExecuteSQL( sqlStr );
                    AfxMessageBox( sqlStr );
                }
                else
                {
                    sqlStr.Format( _T("%s %d NO Codigo = %ld"), aa, ss, pS_DatoV->lVal );
                    AfxMessageBox( sqlStr );
             }

             pS_DatoC->TextGet( aa ); <--------- Always void

                if( pS_DatoC->GetCheck() ) <--------- Always 1
                {
                    sqlStr.Format( _T("%s DELETE FROM %s WHERE Empresa = %s AND Codigo = %ld"), aa, ficheroMySQL, App->m_EmpresaActiva, pS_DatoV->lVal );
//                    m_wndGrid->DoExecuteSQL( sqlStr );
                    AfxMessageBox( sqlStr );
                }
                else
                {
                    sqlStr.Format( _T("%s NO Codigo = %ld"), aa, pS_DatoV->lVal );
                    AfxMessageBox( sqlStr );
             }
            }
        }
    }

    if( pS_DatoV )
        pS_DatoV = NULL;

    if( pS_DatoC )
        pS_DatoC = NULL;
}

Technical Support Jul 9, 2009 - 12:12 PM

There are several lines of code like this in your code snippet:

pS_DatoV = STATIC_DOWNCAST( CExtGridCellVariant, GridCellGet( nIndex, nFila, 0, 0, RUNTIME_CLASS(CExtGridCellVariant) ) );

Where nIndex is the column number. You are initializing different grid cell objects depending on some data format returned by the database query. We suspect you tried to access a check box grid cell when it’s really some other type of grid cell. Please use the following code for testing the check box cells in your grid window:
 //
      // This string will contain message text composed to show in the message box.
      //
CString strMsgBoxMessage;
      //
      // Next line of code gets grid cell in the grid. The  RUNTIME_CLASS( CExtGridCellCheckBox ) parameter will be used
      // for initializing check box cell only if there is no grid cell object initialized yet at the (xx,yy) location.
      //
CExtGridCell * pCell = m_wndGrid.GridCellGet( xx, yy, 0, 0, RUNTIME_CLASS( CExtGridCellCheckBox ) ); 
      ASSERT_VALID( pCell );
      //
      // Next line of code formats the beginning part of text to display in message box.
      //
      strMsgBoxMessage->Format( _T("The grid cell at (column=%d,row=%d) is the object of the %s class type."), xx, yy, str->GetRuntimeClass()->m_lpszClassName );
      //
      // If the grid cell is really the check box grid cell, then append additional sentence to the message box text.
      // Please note, we used the DYNAMIC_DOWNCAST preprocessor function – not STATIC_DOWNCAST
      //
CExtGridCellCheckBox *pDataCellC = DYNAMIC_DOWNCAST( CExtGridCellCheckBox, pCell );
      if( pDataCellC != NULL )
      {
            strMsgBoxMessage += _T("\r\nIt’s really the check box cell and its checked state is ");
            if( pDataCellC->GetCheck() != 0 )
                  strMsgBoxMessage += _T("ON");
            else
                  strMsgBoxMessage += _T("OFF");
            strMsgBoxMessage += _T(".");
      }
      //
      // Finally, display the message box.
      //
      ::AfxMessageBox( LPCTSTR(strMsgBoxMessage) );