I'm very new to windows forms so please don't mind the noob question.
I searched, read and watched videos on how to do this but I am stuck. What I'm trying to do is, access the objects (textbox, label, combobox,etc) between forms. I'd really appriciate if someone can put comments and explain it as simple as possible on how it works so I can get a basic understanding on how things work. So here I have
MainForm (includes a label combobox and buttons that calls different child forms)
private void AddCity_Click(object sender, EventArgs e)
{
AddAddCity _frmAddCity = new AddCity();
_frmAddCity.ShowDialog();
_frmAddCity.Dispose();
}
Addcity (includes multiline textbox, add button, remove button, textbox to enter city name)
public static List<string> citylist
public static List<string> cityNames
private void btnAddCity_Click(object sender, EventArgs e)
{
citylist.Add(txtCityName.Text);
txtCityName.AppendText(txtCityName.Text + "\r\n");
}
private void btnOK_Click(object sender, EventArgs e)
{
mainform.CityCombobox.Items.AddRange(computerlist);//this gives an error
}
private void AddCity_FormClosing(object sender, FormClosingEventArgs e)
{
cityNames.AddRange(citylist);
}
private void AddComputers_Load(object sender, EventArgs e)
{
foreach(string City in cityNames)
{
txtCityName.AppendText(City + "\r\n");
}
}
I created two lists and add the first one to second one so when I close the form I can keep those city names. When re-call the addcity form, I want all the city names in the textbox so I can remove the ones I don't want. I get errors trying to build it since it doesn't work.
Now going back to the mainform, if I select a City from the dropdown box, I want that to be used as a string on all the other child forms. Like frmState and so forth.
Is there a way to create a separate class to clean things up and maybe use that to automate more stuff and use that class in any form I want?
Thank you everyone in advance for their time.