title: Populating combo box in MFC dialog box
body: <p>I've added a combo box to my MFC dialog box. And I've added both a <em>control variable</em> (<code>m_wndImportMode</code>) and a <em>value variable</em> (<code>m_nImportMode</code>).</p>
  
  <p>I'm able to use both variables just fine. And I can use the control variable to populate the control just fine. My problem is where is the correct location to populate my control?</p>
  
  <p>If I populate the combo box before <code>DoDataExchange()</code> then my control variable has not yet been initialized. If I populate the combo box after <code>DoDataExchange()</code>, then it populates fine but the value does not get set.</p>
  
  <pre><code>BOOL COptionsDlg::OnInitDialog()
  {
      // If I populate my combo box here,
      // my control variable is not yet available
  
      // This will ultimately call DoDataExchange()
      CDialog::OnInitDialog();
  
      // If I populate my combo box here,
      // DoDataExchange() has already been called and
      // so it will not have selected the correct item
      // before there were any items
  
      return TRUE;  // return TRUE unless you set the focus to a control
  }
  </code></pre>
  
  <p>Playing with this a little more, I can see I can populate the control before calling <code>CDialog::OnInitDialog()</code> if I use <code>GetDlgItem()</code> instead of my control variable (which has not yet been initialized), and then the default item will correctly be set as I want. But doesn't the MFC framework provide for populating list controls in a dialog box and <em>still</em> using <code>DoDataExchange()</code>?</p>