Reputation: 23
Hi I have a program that:
1- user should first choose an item from a ComboBox
.
Upon the selection, a text file is opened in the background and its contents added to a ListBox
.
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
switch (comboBox2.SelectedIndex)
{
case 0:
listBox3.Items.Clear();
FileInfo file0 = new FileInfo("C:\\hardwaremaintenance.txt");
StreamReader stRead0 =file0.OpenText();
while (!stRead0.EndOfStream)
{
listBox3.Items.Add(stRead0.ReadLine());
}
break;
case 1:
listBox3.Items.Clear();
FileInfo file1 = new FileInfo("C:\\NetworkManagement.txt");
StreamReader stRead1 =file1.OpenText();
while (!stRead1.EndOfStream)
{
listBox3.Items.Add(stRead1.ReadLine());
}
break;
case 2:
listBox3.Items.Clear();
FileInfo file2 = new FileInfo("C:\\Software.txt");
StreamReader stRead2 =file2.OpenText();
while (!stRead2.EndOfStream)
{
listBox3.Items.Add(stRead2.ReadLine());
}
break;
case 3:
listBox3.Items.Clear();
FileInfo file3 = new FileInfo("C:\\SyriatelApplications.txt");
StreamReader stRead3 =file3.OpenText();
while (!stRead3.EndOfStream)
{
listBox3.Items.Add(stRead3.ReadLine());
}
break;
case 4:
listBox3.Items.Clear();
FileInfo file4 = new FileInfo("C:\\NewHardwareRequest.txt");
StreamReader stRead4 =file4.OpenText();
while (!stRead4.EndOfStream)
{
listBox3.Items.Add(stRead4.ReadLine());
}
break;
}
}
2-user select an item from the (recently) added items in the listbox (from step 1) and upon this action it again opened a new text file where its filled with a text from this way of format, where the " | " is the separation symbol
private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
{
int itemsCount = listBox3.Items.Count;
string[] items = new string[itemsCount];
for (int i = 0; i < itemsCount; i++)
items[i] = listBox3.Items[i].ToString();
AND my brain suddenly stuck here.
The next step was supposed to take each item in the ListBox
and connect it with the row from the last opened file WHERE the item selected == the first word in any of the rows.
What I don't know how to do it is:
ListBox
with the fist word in any of the rows in the second file.And if they match, I want to use the remaining info in the row to fill labels and textboxes.
The interface of the program as the following
I'm really sorry if I confused you, but I'm not that experienced in programming
Upvotes: 0
Views: 646
Reputation: 273274
A few tips to get you started:
string[] items
to your class.switch()
use Refactor|Extract methodSystem.IO.File.ReadAllLines(fileName)
str=listbox3.SelectedItem
) in another file use lines[i].Contains(str)
Upvotes: 2