Loading listbox from a recordset

Discussion in 'C++' started by vermetpa@gmail.com, Dec 1, 2006.

  1. Guest

    Hello,

    My problem involves loading a listbox from a recordset. 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

    }

    -- Joseph
    , Dec 1, 2006
    #1
    1. Advertising

  2. Salt_Peter Guest

    wrote:
    > Hello,
    >
    > My problem involves loading a listbox from a recordset. 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
    >
    > }
    >
    > -- Joseph


    Please ask your question in a relevent newsgroup. We do C++ here, not
    proprietary languages.
    You might find a relevent newsgroup by consulting:
    http://www.parashift.com/c -faq-lite/how-to-post.html
    section 5.4
    Has an extended list of relevent groups that may serve you better.
    Salt_Peter, Dec 1, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. blenderdude
    Replies:
    0
    Views:
    787
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    392
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    864
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,310
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. Hung Huynh
    Replies:
    8
    Views:
    289
    Bob Barrows
    Sep 24, 2003
Loading...

Share This Page