Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Access listbox from view's class

Access listbox from view's class

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    danag
    wrote on last edited by
    #1

    How do I initialize the dialog's list box in the View's member function ? Actually, I want to display a record in the listbox in the view button down handler fucntion? When I try to do, my program aborts in the listbox.AddString(...) fucntion? What could be possible wrong?

    D 1 Reply Last reply
    0
    • D danag

      How do I initialize the dialog's list box in the View's member function ? Actually, I want to display a record in the listbox in the view button down handler fucntion? When I try to do, my program aborts in the listbox.AddString(...) fucntion? What could be possible wrong?

      D Offline
      D Offline
      Dave Bryant
      wrote on last edited by
      #2

      Sounds like the listbox hasn't been created yet. If the listbox is within a dialog class, you shouldn't initialise it until you receive a WM_INITDIALOG message - the OnInitDialog() method is called. So, in this case you could pass the relevant information to the dialog constructor, and then in the OnInitDialog() method of the dialog class, initialise the listbox there. Dave

      D 1 Reply Last reply
      0
      • D Dave Bryant

        Sounds like the listbox hasn't been created yet. If the listbox is within a dialog class, you shouldn't initialise it until you receive a WM_INITDIALOG message - the OnInitDialog() method is called. So, in this case you could pass the relevant information to the dialog constructor, and then in the OnInitDialog() method of the dialog class, initialise the listbox there. Dave

        D Offline
        D Offline
        danag
        wrote on last edited by
        #3

        Yes, u are correct. But I would like to initailize with the data I read from the database. I am reading the records in the View's member function, so how do i pass the values read to the listbox?

        D 1 Reply Last reply
        0
        • D danag

          Yes, u are correct. But I would like to initailize with the data I read from the database. I am reading the records in the View's member function, so how do i pass the values read to the listbox?

          D Offline
          D Offline
          Dave Bryant
          wrote on last edited by
          #4

          The same principle applies: Something like: void CMyView::DoSomething() { CMyDialog dlg( this ); for ( each value in database ) { CString strValue = GetValueFromDataBase(); dlg.AddValue( strValue ); } if ( IDOK == dlg.DoModal() ) { // Do something with it } else { // Panic / shoot user } } class CMyDialog : public CDialog { // All the usual stuff public: void AddValue(const CString& strValue); private: CStringList m_lstValues; }; void CMyDialog::AddValue(const CString& strValue) { m_lstValues.AddTail( strValue ); } BOOL CMyDialog::OnInitDialog() { CDialog::OnInitDialog(); // Add the values for ( POSITION pos = m_lstValues.GetHeadPosition() ; pos != NULL ; ) m_lstCtrl.AddString( m_lstValues.GetNext( pos ) ); return TRUE; } Dave

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups