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
Loading
Amit ChoudharyPosted Jul 7, 2010, 12:59 AM
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 HosseiniPosted Jul 7, 2010, 1:41 AM
thanks amit, it works now