Geeks Talk

Prepare for your Next Interview




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

This is a discussion on Loading a ListBox from a Recordset (in C++) within the C and C++ forums, part of the Software Development category; 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 ...


Go Back   Geeks Talk > Software Development > C and C++

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 12-29-2006
Junior Member
 
Join Date: Dec 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
ultranet is on a distinguished road
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
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-29-2006
Junior Member
 
Join Date: Dec 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
teja5689 is on a distinguished road
Red face Re: Loading a ListBox from a Recordset (in C++)

the solution is excellent


where did u get the source code??
Reply With Quote

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved