473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Loading listbox from a recordset

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 '06 #1
1 1984

ve******@gmail.com 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.

Dec 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: melanie | last post by:
Hi, I open a recordset with a SQL query as its source. Then, i set the listbox.recordset = to the recordset i just opened. But, the fields appear in the listbox columns in a different order...
6
by: AAJ | last post by:
Hi all I have a listbox on a form. If I set its rowsource directly, and the query in the rowsourse returns no data, then the displayed listbox is empty (exactly as you would expect) ...
13
by: Gittyup | last post by:
Help please, We have a form, based on a query, that contains a listbox. The contents of the listbox are based on the results of the query. When the form is opened, the user selects an item...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
4
by: collie | last post by:
HI, I need to populate 2 listboxes from a db. When the page loads then the first listbox needs to be populated and based on selection from that listbox the second listbox needs to be populated...
6
by: Mark | last post by:
Hello. I have a listbox whose rowsource is set to a saved query (call it "qry_customer_list.") When I add customers to my database, I call the listbox Requery method so that the listbox will...
4
by: mrmagoo | last post by:
I'm building a vb.net Forms project that is getting data from a SQL Server database. One of the main goals of the project is to be really responsive to events, such as textbox change events. I...
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
7
by: EManning | last post by:
I'm using A2003 connected to a SQL 2000 backend. This is not an adp. I have a table which I store 0 and -1 for 2 bit fields. I have a listbox on a form based on a query of this table. The...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.