Hi Guys,
I am trying to load a combobox from a text file (Test.txt).Every thing goes fine while I capture the elements in Test.txt line by line like:
One
Two
Three
but when I store a the elements as a CSV format like One, Two, Three the combo box return all of them in one line.
Could you please let me know how should I modify the code to be able to seperate elements by comma?
private void btnLoad_Click(object sender, EventArgs e)
{
string path = "D:\\Test.txt";
StreamReader sr = new StreamReader(path);
while (sr.Peek() >= 0)
{
comBox.Items.Add(sr.ReadLine());
}
comoBox.SelectedIndex = -1;
}
Best Regards
Load from Text file into ComboBox
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Amit ChoudharyRank #145 · 15.8K reputationPosted Jul 6, 2010, 8:59 PM EDT
try to convert the return type of sr.ReadLine() to string.
then apply split function on that string..
like String RLine=sr.ReadLine().ToString();
ComboBox.Items.AddRange(RLine.Split(','));
Hope it works for you.
Please mark "Do you like this post" if it helps you.
Behrouz Hosseini64 reputationPosted Jul 6, 2010, 9:41 PM EDT
thanks amit, it works now