954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

VC++ combo box help

I have two dialogs as I told before.there is a combo box in the first dialog.i have a text box in the second dialog.when i click a button, i get the second dialog in which the text box is present.i get the data in the text box in the combo box when i click the ok button .have written code for that.my problem is , i have to see all the data that i enter in the text box in the second dialog into the combo box in first dialog.now what happens is, i can only see the last entered item.i have written it i the OnOK function ,but have commented CDialog::OnOk();
I need to enter details as long as i want and see them all in the first combo box. what to do?
Code in second dialog:

CString i;
fstream f;
f.open("C:\\myfile.txt",ios::app); 
printf("\n");

GetDlgItemText(IDC_EDIT2,str_name);
f.write(str_name.GetBuffer(str_name.GetLength()),str_name.GetLength()); 
f<<endl;

m_combo.AddString(str_name); 

m_edit3.SetWindowText(_T(""));
f.close();

in first dialog:

Add cd;
cd.DoModal();
m_selcam.AddString(cd.str_name);
camproject
Light Poster
26 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 

>>f.write(str_name.GetBuffer(str_name.GetLength()),str_name.GetLength());

This will not help the problem you describe, but you should be using the >> operator for that, not the binary write() function.
f << (LPCTSTR)str_name << "\n";

Note that you don't need to call GetBuffer() because CString has overloaded the LPCTSTR operator that does similar thing -- when you use GetBuffer() you also should call ReleaseBuffer().

How much text are you attempting to add to one line of the ComboBox anyway? Maybe what you want is a list box which will show larger amount of text for each item.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

i have to add only one line at a time.what i need is add he item in second dialog to first dialog's combo box as soon as I hit "Add" button each time.

camproject
Light Poster
26 posts since May 2008
Reputation Points: 10
Solved Threads: 0
 
i have to add only one line at a time.what i need is add he item in second dialog to first dialog's combo box as soon as I hit "Add" button each time.

You might change the second dialog's constructor to take e.g. a pointer to the first dialog's CComboBox and then use that pointer to add each item in the second dialog i.e. something like

// in the first dialog box ...
// Pass in the address of the combobox (m_selcam) ...
Add cd(NULL, &m_selcam);
cd.DoModal();

/////////////////////////////////////////////
// in the second dialog box ...
...
GetDlgItemText(IDC_EDIT2,str_name);
// m_selcamPtr is a pointer to the combobox 
// received via the dialog box's constructor
m_selcamPtr->AddString(str_name);
...
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You