Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic ComboBox

Status
Not open for further replies.

Jiko

Technical User
Apr 5, 2002
35
SE
We have a map with files that we want to be shown in a combobox. The number of files in the map varies. When we chose a file from the combobox, that filename should be saved as a CString. We use this CString when we send the file on a comport.

 
I don't know about others but what do you mean by a map? Do you mean a map as in how to get from A to B?

I also don't quite follow what you are trying to achieve here.

William
Software Engineer
 
Hi,

Do you mean that you want the contents of a directory displayed as items in a combobox?

Branko
 
Well if you are using the CListBox Object you can use the Dir method of it to populate the list. Then use the MyList.GetText (MyList.GetCurSel(), myString ) to return the selected filename in your CString object.

HTH


William
Software Engineer
ICQ No. 56047340
 
We solved it like this.
This part put the names in the file LK-lista.txt in the combobox.

BOOL CST7kommDlg::OnInitDialog()
CString Filnamn = "C:\\Mina dokument\\Laddningskurvor\\LK-lista.txt";
CStdioFile file;
BOOL fSuccess = file.Open(
_T(Filnamn),
CFile::modeRead |
CFile::shareDenyRead |
CFile::typeText
);

CString strOutput;
while(file.ReadString(strOutput))
m_xCombo.AddString(strOutput);


This part opens the file chosed in the combobox.
char fil2[10];
int h=m_xCombo.GetCurSel();
if (h == CB_ERR){
strcpy(errstring,"Välj en laddningskurva.");
MessageBox(errstring);
}
else{
m_xCombo.GetLBText(h,fil2);
UpdateData(FALSE);
CString filnamn = "C:\\Minadokument\\Laddningskurvor\\";
Filnamn +=fil2;
Filnamn += ".txt";
CStdioFile file;
fSuccess = file.Open(
_T(Filnamn), CFile::modeRead | CFile::shareDenyRead |
CFile::typeText
);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top