I previously created a program that displays data from a text file into a listview and users are able to click a name in the listview and it displays the phone number for that name. Now I'm trying to add a new form to the program that allows the user to select a name from a combobox which then displays the name in a textbox and allows a user to change the name and save it in the text file.
Anyways, I'm trying to make the load event from the original program accessible in the new form and I can't seem to figure out how to do that. Here is my code:
public partial class VendorsDictionary : Form
{
public VendorsDictionary()
{
InitializeComponent();
}
private Dictionary<string,string> vendorPhones = new Dictionary<string,string>();
public void VendorsDictionary_Load(object sender, EventArgs e)
{
string currentLine;
string[] fields = new string[2];
StreamReader vendorReader = new StreamReader("Vendor.txt");
while (vendorReader.EndOfStream == false)
{
currentLine = vendorReader.ReadLine();
fields = currentLine.Split(',');
vendorPhones.Add(fields[1], fields[6]);
string[] name = { fields[1] };
string[] city = { fields[3] };
string[] state = { fields[4] };
string[] zipcode = { fields[5] };
string[] phone = { fields[6] };
for (int i = 0; i < name.Length; i++)
{
lvDisplay.Items.Add(new ListViewItem(new[] { name[i], city[i], state[i], zipcode[i] }));
}
}
vendorReader.Close();
}
private void lvDisplay_SelectedIndexChanged(object sender, EventArgs e)
{
if (lvDisplay.SelectedItems.Count>0)
{
ListViewItem item = lvDisplay.SelectedItems[0];
lblName.Text = item.SubItems[0].Text;
lblPhone.Text = vendorPhones[item.SubItems[0].Text];
}
}
private void btnUpdate_Click(object sender, EventArgs e)
{
UpdateVendor updateVendor = new UpdateVendor();
updateVendor.Show();
}
}
I've tried changing it to static and a number of other ideas I've found here but can't seem to get it to work. Any help would be appreciated!