Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Populating combo box dynamically in a form

Posted on 2003-03-19
8
Medium Priority
?
301 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
5 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month10 days, 22 hours left to enroll

572 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