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);

Recommended Answers

All 3 Replies

>>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.

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.

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);
...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.