How to fill a combobox in c ++ mfc with id and description?

0

I have this function that fills the combobox in C ++ mfc but I do not know how to save the id and the description in the combobox, since it currently does it with the pure description. In c # a pairvalue object is used to do this, but I do not find c ++ mfc. if someone could guide me.

bool CDlgSolicitudes::fObtenerCompradores()
{
CString sConsulta;
bool bRegresa=false;


if( odbc.Open("PostgreSQL", g.server, g.user, g.password , g.database) )
{
    sConsulta.Format("select numempleado, nombreempleado from fun_inconsultarcompradores()");

    CConsultarCompradores crSQL( &odbc );
    if( crSQL.Exec( sConsulta ) )
    {

        m_cbCompradores.InsertString(-1, "Selecciona un comprador");
        crSQL.activarCols();
        while( crSQL.Leer() )
        {
            CString nomComprador;
            nomComprador.Format("%s",crSQL.nomComprador);
            nomComprador = nomComprador.Trim();
            m_cbCompradores.AddString(nomComprador);

        }
        bRegresa = true;
        odbc.Close();
    }
    else
    {
        crSQL.odbc->GetLastError(crSQL.GetHstmt()); 
        CString error;
        error.Format("[fObtenerCompradores] %s", crSQL.odbc->m_szErrorMsg);
        odbc.Close();
        AfxMessageBox(error);
    }
}
else
{
    CString error;
    error.Format("[fObtenerCompradores] %s", odbc.m_szErrorMsg);
    odbc.Close();
    AfxMessageBox(error);
}

    return bRegresa;
}

Example: If my function fun_inconsulting buyers () I get the following: 435 - BUYER 1 778 - BUYER 2 921 - BUYER 3

Therefore the combo will fill it with the descriptions: BUYER 1 BUYER 2 BUYER 3

But if I want to save the selected buyer in bd, but nothing else, how can I do it if in the combo I only have the description.

    
asked by Pedro Quiñonez 23.08.2017 в 01:09
source

1 answer

0

Hello!   I imagine that with ID you refer to the identifier that identifies (sorry for the redundancy) the element inside the ComboBox and in effect you only have the member functions InsertString and AddString and then for get each member using FindStringExact , FindString and GetLBText knowing the ordinal of the element. But in principle this should not give you problems, right? since selecting the element of the ComboBox the function returns the ordinal of it with GetCurSel and with it accessing the selected content by means of GetLBText (GetCurSel (), value) . I hope it helps you Courage

    
answered by 23.08.2017 в 07:57