?
Solved

Populating combo box dynamically in a form

Posted on 2003-03-19
8
Medium Priority
?
296 Views
Last Modified: 2013-11-20
Hi,

I want to populate a combo box in a form dynamically....this is as far as i have got.....



int CPocketViewPointView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{

     if (CFormView::OnCreate(lpCreateStruct) == -1)
          return -1;
     // TODO: Add your specialized creation code here
     populateCombo();
     return 0;
}


void CMyView::populateCombo()
{
     for(int i=0;i<m_ccf.m_systemNames.GetSize(); i++)
          m_cbSystemNames.AddString(m_ccf.m_systemNames[i]);
     if(m_cbSystemNames.GetCount() > 0)
          m_cbSystemNames.SetCurSel(0);
     m_cbSystemNames.UpdateData(false);
     m_cbSystemNames.Invalidate(true);

}

Thank you.
0
Comment
Question by:vkudchadkar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 1

Expert Comment

by:jadams117
ID: 8170830
Is this code taken directly from your source?  The OnCreate() function is a member of CPocketViewPointView, and the populateCombo is a member of CMyView

Otherwise, the code looks fine to me, though I'm not sure the UpdateData() and Invalidate() calls are necessary (Or, at least they're not in a dialog - I just tried it)

Jad
0
 

Author Comment

by:vkudchadkar
ID: 8170904
Thanks Jad for your time.

The code is from my source.

I am still trying to find the error. For some reason, the AddString is not working....i get the return code as 0...which is not an error....but when i check the count it is 0...

the code works fine in InitDialog of a dialog box but not in the Form

Thanks

Vishal
0
 

Author Comment

by:vkudchadkar
ID: 8171016
i managed to populate it....no change in the code...all i did was add data while creating the combo box using the resource editor.....have no clue y it worked....mebbe someone knows why....

thanks everyone.
Vishal
0
 

Accepted Solution

by:
ramanan_r earned 80 total points
ID: 8171534
hai

For Loading the combo dynamically without using adding the data in the resource editor try to call the
populatecombo() in the view's OnInitialUpdate().This is where the initialization for views are to be done just like the OnInitDialog() for dialogs.

thanks
Ramanan
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 8171706
The reason it doesn't work in OnCreate is the MFC object (m_cbSystemNames) has not been attached to the combo HWND yet. If you compile in debug mode you should see, for the wrong code, an ASSERT on an IsWindow type line in something like AFXWIN.INL
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question