Results 1 to 2 of 2

Thread: Loading a ListBox from a Recordset (in C++)

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Answers
    2

    Loading a ListBox from a Recordset (in C++)

    Hello,

    My problem involves loading a listbox from a recordset. This is a standard MFC project with database support.

    I hope this is the right spot to ask this kind of question.

    To start off this is the code in the initial update:

    void CEmployee4View::OnInitialUpdate()
    {
    m_pSet = &GetDocument()->m_employee4Set;

    m_pSet->m_strFilter="[Departments].[DeptID] = [Employees].[DeptID] AND [Managers].[ManagerID] = [Departments].[ManagerID]";

    m_pSet->m_strSort="[Departments].[DeptName]";

    CRecordView::OnInitialUpdate();
    GetParentFrame()->RecalcLayout();
    ResizeParentToFit();

    }

    This is fine. I have created a function called LoadListBox which is
    called in the DoDataExchange. (You will see there are two other fields
    which are textboxes).

    void CEmployee4View:: DoDataExchange(CDataExchange* pDX)
    {
    CRecordView:: DoDataExchange(pDX);
    //{{AFX_DATA_MAP(CEmployee4View)
    DDX_FieldText(pDX, IDC_txtManager, m_pSet->m_ManagerName, m_pSet);
    DDX_FieldText(pDX, IDC_txtDepartment, m_pSet->m_DeptName, m_pSet);
    LoadListBox();
    //}}AFX_DATA_MAP

    }

    The problem with my LoadListBox function so far is that it only works
    for going forward in the recordset. I can't quite grasp how to allow it
    go backward. If you could take a look at the code, and help me come up
    with a solution, it would be greatly appreciated.

    void CEmployee4View::LoadListBox()
    {
    CListBox* pLB = (CListBox*) GetDlgItem(IDC_lstEmployees); //the IDC of
    your ListBox
    CString ThisDept = m_pSet->m_DeptID2;
    CString PrevDept = ThisDept;

    pLB->ResetContent();

    // if going forward

    if (ThisDept >= PrevDept) {

    while( m_pSet->m_DeptID2 == ThisDept) {

    pLB->AddString(m_pSet->m_EmployeeName);

    m_pSet->MoveNext();

    if (m_pSet->IsEOF() ) break;

    }

    m_pSet->MovePrev();

    } // end if

    else {

    while(m_pSet->m_DeptID2 == ThisDept) {

    pLB->AddString(m_pSet->m_EmployeeName);

    m_pSet->MovePrev();

    if(m_pSet->IsBOF() ) break;

    }

    m_pSet->MoveNext();

    } // end if

    }


    Please suggests

    Thanks for your valuable time


  2. #2
    Junior Member
    Join Date
    Dec 2006
    Answers
    1

    Red face Re: Loading a ListBox from a Recordset (in C++)

    the solution is excellent


    where did u get the source code??


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact