Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Loading listbox from a recordset

Reply
Thread Tools

Loading listbox from a recordset

 
 
vermetpa@gmail.com
Guest
Posts: n/a
 
      12-01-2006
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:oDataExchange(CDataExchange* pDX)
{
CRecordView:oDataExchange(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

 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      12-01-2006

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:oDataExchange(CDataExchange* pDX)
> {
> CRecordView:oDataExchange(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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox item added with client scripts not submitting with ASP:Listbox Simon Prince ASP .Net 2 10-19-2004 04:11 PM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
click listbox and refresh another listbox DC Gringo ASP .Net 0 04-06-2004 02:13 AM
RecordSet.Move or RecordSet.AbsolutePosition?? Hung Huynh ASP General 8 09-24-2003 11:07 AM
Re: now desparate! - 1st listbox contents disappears when 2nd listbox appears? blenderdude ASP .Net 0 08-03-2003 10:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57