I have a text file which contain following type item
wett45456,4556,45657,898
tyu5878,4566,7989,55565
now i have a windowform on that form ihave a combobox now i want fill combobox with firstitem of each row wett45456,tyu5878
Thank you
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Tamizhvendan SPosted May 11, 2011, 8:08 AM
foreach (var line in lineOfContents)
{
string[] tokens = line.Split(',');
comboBox1.Items.Add(tokens[0]);
}
Ankit NandekarPosted May 11, 2011, 8:28 AM
string[] s = File.ReadAllLines("your text file path");
foreach (string line in s)
{
string[] str= line.Split(',');
comboBox1.Items.Add(str[0]);
}
Note: use namespace using System.IO; .
Dorababu MekaPosted May 11, 2011, 8:08 AM
private void FillComboBox()
{
string[] line1=null;
try
{
StreamReader sr = new StreamReader(@"C:\Documents and Settings\Administrator\Desktop\cmb.txt");
string line = sr.ReadLine();
while (line != null)
{
if (line.Contains(","))
{
line1 = line.Split(',');
comboBox1.Items.Add(line1[0]);
line = sr.ReadLine();
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
}
Dorababu MekaPosted May 11, 2011, 7:52 AM