Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


// Get the number of items in the array
SizeBusiness = sizeof(Business) / sizeof(CString);
SizePersonal = sizeof(Personal) / 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);

return TRUE; // return TRUE unless you set the focus to a control
}


  1. Test your program

  2. After testing the dialog box, close it and return to MSVC.

  3. Add a BN_CLICKED Event Handler for the IDC_RDO_BUSINESS radio button
    and change the name of the function to OnSelectBusiness

  4. Add a BN_CLICKED Event Handler for the IDC_RDO_PERSONAL radio button
    and change the name of the function to OnSelectPersonal

  5. Implement both events as follows:


void CTableWizardDlg::OnSelectBusiness()
{
// TODO: Add your control notification handler code here
// Empty the list
m_SampleTables.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);
}

void CTableWizardDlg::OnSelectPersonal()
{
Free download pdf