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 }
Actually I don't think that it is right place to ask C++ questions, but anyway, can you show me please where exactly in your code you have a problem ?
All the logic should be in the LoadListBox. The problem is it does not know whether I am going backward of forward in the record set. If it did, there would be no problem.