Chapter 20: List-Based Controls Visual C++ and MFC Fundamentals
BOOL CTableWizardDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
// Select the Business radio button
m_SelectBusiness.SetCheck(1);
// Get the number of items in the array
SizeBusiness = sizeof(Business) / sizeof(CString);
SizePersonal = sizeof(Personal) / sizeof(CString);
SizeContacts = sizeof(Contacts) / sizeof(CString);
SizeAddresses = sizeof(Addresses) / sizeof(CString);
SizeEmployees = sizeof(Business) / sizeof(CString);
SizeCustomers = sizeof(Business) / sizeof(CString);
SizeVideoCollection = sizeof(VideoCollection) / sizeof(CString);
SizeCategories = sizeof(Categories) / sizeof(CString);
SizeAuthors = sizeof(Authors) / sizeof(CString);
SizeBooks = sizeof(Books) / sizeof(CString);
// Fill out the Sample Tables list with the Business items
for(int i = 0; i < SizeBusiness; i++)
m_SampleTables.AddString(Business[i]);
// Select the first item in the Sample Tables list box
m_SampleTables.SetCurSel(0);
// Fill out the Sample Fields list box
for(int j = 0; j < SizeContacts; j++)
m_SampleFields.AddString(Contacts[j]);
// Select the first item in the Sample Fields list box
m_SampleFields.SetCurSel(0);
return TRUE; // return TRUE unless you set the focus to a control
}
- To make sure that the Sample Fields list is updated when one of the radio buttons is
selected, change the OnSelectBusiness() and the OnSelectPersonal() functions as
follows:
void CTableWizardDlg::OnSelectBusiness()
{
// TODO: Add your control notification handler code here
// Empty the list
m_SampleTables.ResetContent();
m_SampleFields.ResetContent();
// Fill out the list with Business items
for(int i = 0; i < SizeBusiness; i++)
m_SampleTables.AddString(Business[i]);
// Select the first item in the list
m_SampleTables.SetCurSel(0);