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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Tamizhvendan S2 reputationPosted May 11, 2011, 4:08 AM EDT
foreach (var line in lineOfContents)
{
string[] tokens = line.Split(',');
comboBox1.Items.Add(tokens[0]);
}
Dorababu MekaRank #457 · 5.5K reputationPosted May 11, 2011, 3:52 AM EDT
Dorababu MekaRank #457 · 5.5K reputationPosted May 11, 2011, 4:08 AM EDT
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);
}
}
Ankit NandekarRank #703 · 3.4K reputationPosted May 11, 2011, 4:28 AM EDT
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; .