Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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



  1. Change its ID to IDC_SELECTEDFIELDS and remove the check mark of its Sort
    property or set it to False

  2. Add a CListBox Control Variables for the IDC_SELECTEDFIELDS control and
    name it m_SelectedFields

  3. Add a Button between the right list boxes. Set its ID to
    IDC_BTN_SELECTONE and its Caption to >

  4. Add a CButton Control Variable for the > button and name it m_SelectOne

  5. Add another Button under the previous one. Set its ID to
    IDC_BTN_SELECTALL and its Caption to >>

  6. Add a CButton Control Variable for the >> button and name it m_SelectAll

  7. Add another Button under the previous one. Set its ID to
    IDC_BTN_REMOVEONE and its Caption to <

  8. Add a CButton Control Variable for the < button and name it m_RemoveOne

  9. Add another Button under the previous one. Set its ID to
    IDC_BTN_REMOVEALL and its Caption to <<

  10. Add a CButton Control Variable for the << button and name it m_RemoveAll

  11. First of all, when the dialog box opens, the Selected Fields list is empty, which
    means the Remove buttons are not useful. Therefore, we should disable them. To do
    this, add the following two lines to the OnInitDialog() member function:


// Since the Selected Field list box is empty, disable the Remove buttons
m_RemoveOne.EnableWindow(FALSE);
m_RemoveAll.EnableWindow(FALSE);

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


  1. Add a BN_CLICKED Event Handler for the > button and name it OnSelectOne

  2. To be able to select an item from the Sample Fields list and transfer it to the Selected
    Fields list box, implement the function as follows:


void CTableWizardDlg::OnSelectOne()
{
// TODO: Add your control notification handler code here
// Variable that identifies what item is selected in the sample fields
CString SourceSelected;

// Find out what item is selected
// Store it in the above variable
m_SampleFields.GetText(m_SampleFields.GetCurSel(), SourceSelected);

// Add the item to the Selected Fields list box
m_SelectedFields.AddString(SourceSelected);
}


  1. To enhance the application, we need to make sure that the user can double-click an
    item in the Sample Fields list box and obtain the same behavior as if the > button had
    been clicked
    Therefore, add an LBN_DBLCLK for the IDC_SAMPLEFIELDS list box and name
    it OnDblClkSampleFields

  2. Implement it as follows:

Free download pdf