Loading listbox from a recordset

V

vermetpa

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
 
S

Salt_Peter

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top