I am trying to populate a combo box in VS2012 C++ Forms app. I am able to populate the box using the Streamreader. But the over all goal is I need the text file to work similar to a SQL database ie,
If I have a text file like this
1, 5
2, 6
3, 7
4, 8
I need to populate the combo box with the 1,2,3,4
then I need to be able to take the value (after the user has selected the combo box value) and do a Item search. So if the user selected 3, I will need to open the file and find 3, but return 7 as the value.
Any help would be nice here is the function that I am using right now to get the combo box to populate using just a normal text file like.
private: void FillCompanyBox(void){
try
{
// Open File Using A Stream Reader Object
StreamReader ^streamReader = gcnew StreamReader("Company_Name.txt");
try
{
// Read Each Line Until End Of File
while (!streamReader->EndOfStream)
{
// Read Line (Trimming Whitespace)
String ^lineOfFile = streamReader->ReadLine()->Trim();
// Add It To Drop Down If It Is Not Empty
if (lineOfFile->Length > 0)
{
U_Company_Name->Items->Add(lineOfFile);
}
}
}
finally
{
// Delete Stream Reader If It Was Created
if (streamReader)
{
delete (IDisposable ^)streamReader;
}
}
}
catch (Exception ^e)
{
// Display Error
MessageBox::Show(e->ToString());
}
}