How addstring to combobox??

I Create a vc MDI project and select
MyToolBar as "internet explore rebars"
type ,then i edit Dialog resource
"IDR_MAINFRAME" AND add a combobox control on it and create a class for this dialog ,after this ,I Initial combobox in CMyDlg::OnInitDialog() with code:

CComboBox *pcmbBox
=(CComboBox *)GetDlgItem(IDC_COMBOBOX);
pcmbBox->addstring("1");

but after I run this MDI Application I can't find item "1" in the combobox.
why???
experts help me!! !
lxtsyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Vinayak KumbarSr Program ManagerCommented:
Hi,

>but after I restart the Application I can't find item "1" in the
                                combobox.

Once u restart, it will not be there until u add it once again I think.(As I have not used Rebars, I am interested in this Q).

Regards,

VinExpert
0
lxtsyAuthor Commented:
Edited text of question.
0
lxtsyAuthor Commented:
Edited text of question.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

inprasCommented:
Go to the dialog where U have inserted the combo box and click on the pulldown arrow a verticle arrow comes click it drag the combo box size I mean increase the combo box size U will get string
Regards
0
jhanceCommented:
I find it VERY difficult to believe that the following code even COMPILES much less runs:

pcmbBox->addstring("1");


There is _NO_ addstring() method to the CComboBox class.  The closest match and what I think you should use is:

pcmbBox->AddString("1");

I bring this up because there is MORE here than you are telling us.  Incomplete information makes it very difficult to provide you with good help.
0
migelCommented:
Hi!
try
pcmbBox->SetCurSel(0);
0
chensuCommented:
I think inpras is right.
0
Shahzad_mcaCommented:
There are 2 ways to add data to Combobox.

1. U can add it at design time as suggested by inpras..

2. U can add data at run time...
pcmbBox->AddString("Shahzad");
  this should do, but the difficulty with u is that the item gets added but U r unable to see it,
 for that U should try this...

 pcmbBox->InitStorage(2,500);

 pcmbBox->SetWindowPos(&wndTop,0,0,200,120,SWP_NOMOVE);

Let me know the result....

thanks...
0
lxtsyAuthor Commented:
How To Add Item to ComboBox Control which In DialogBar??
0
inprasCommented:
Hi Shahzad_mca

I never told him/her to insert data during design time I told him/her to extend the size of combo box U know to drag it down to see the pulldown menu type data
Regards
0
lxtsyAuthor Commented:
How To Add Item to ComboBox Control which In DialogBar??
0
lxtsyAuthor Commented:
When I AddString(),there is Debug Assertion  failed message!!
0
Shahzad_mcaCommented:
U may not be getting the handle of the ComboBox ...
Check it !!!!
0
MaroyCommented:
The following code works for me you might want to try it.

find the function

int CMainFrame::OnCreate
(LPCREATESTRUCT lpCreateStruct)
{
     .
     .
     .
if (!m_wndReBar.Create(this) ||
    !m_wndReBar.AddBar(&m_wndToolBar) ||
    !m_wndReBar.AddBar(&m_wndDlgBar))
{
  TRACE0("Failed to create rebar\n");
  return -1;      // fail to create
}
// new code starts here
 CComboBox* pmyComboBox = (CComboBox*)
     m_wndDlgBar.GetDlgItem(IDC_COMBO1);

  pmyComboBox->AddString("One");
  pmyComboBox->AddString("Two");
  pmyComboBox->SetCurSel(0);
     .
     .
     .
}

This is pretty much what you have
already tried with the addition of
SetCurSel(0);

If you do not see "One" in the combo
box I suspect you have selected

"Owner draw" = to something other than
"No" in the combo box's properites.

"Owner draw" is on the "Styles" tab.

I would not be suprised if there are
other setting in the Combo box properties which would also keep it from doing what you want.  The code snipet above works with a "default"
combo box as "dropped" from the the controls tool bar.

In closing you can preset the combo box's data (strings) by using the "data" tab on the combo box's properities. If you do this the combo
box is preloaded with string but you will not see one until you push the extend thumbnail

PS one last point. Did you create an instance of your new class?  I suspect if check MainFrm.h you will the following:
 CDialogBar m_wndDlgBar;
 
and

CMainFrame::OnCreate
is still in its original Wizard created
state. Which is a long way of saying
you may not even be displaying your
derived class dialog bar ....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nyangCommented:
How can I make the items on CDialogBar active?  I have 2 buttons on the CDialogBar object, and they are all grayed.  I tried various methods, and not much success.  Please help.  Thanks in advance.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.