Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals



  1. In the Function Handler Name edit box, change the name to OnChangeSampleTables

  2. Click Add and Edit

  3. Implement the function as follows:


void CTableWizardDlg::OnChangeSampleTables()
{
// TODO: Add your control notification handler code here
// Before filling out the Sample Fields list box, empty it first
m_SampleFields.ResetContent();

// This string variable will identify the selected table
CString ItemSelected;

// Get the name of the item selected in the Sample Tables list box
// and store it in the CString variable declared above
m_SampleTables.GetText(m_SampleTables.GetCurSel(), ItemSelected);

// Fill out the Sample Fields list box according to the selected table
if( ItemSelected == "Contacts" )
{
for(int i = 0; i < SizeContacts; i++)
m_SampleFields.AddString(Contacts[i]);
}
else if( ItemSelected == "Customers" )
{
for(int i = 0; i < SizeCustomers; i++)
m_SampleFields.AddString(Customers[i]);
}
else if( ItemSelected == "Employees" )
{
for(int i = 0; i < SizeEmployees; i++)
m_SampleFields.AddString(Employees[i]);
}
else if( ItemSelected == "Addresses" )
{
for(int i = 0; i < SizeAddresses; i++)
m_SampleFields.AddString(Addresses[i]);
}
else if( ItemSelected == "VideoCollection" )
{
for(int i = 0; i < SizeVideoCollection; i++)
Free download pdf