I just created a form with many combobox but they only use the same data. At the first time, I load the data for every click on the radiobutton, but it takes some time and it's so annoying. So instead of loading the combobox everytime I click a radiobutton, I want it to load just one time when the app start.
The code below is to create the global combobox which can be called anywhere in the form.
public partial class Form1 : Form
{
//code to get the requester below
public List<XMLSoccerCOM.Team> all_team = requester.GetAllTeams();
public List<XMLSoccerCOM.League> all_league = requester.GetAllLeagues();
public ComboBox combo_team = new ComboBox(); //global combo_team
public ComboBox combo_league = new ComboBox(); //global combo_league
//the rest of the code
}
And inside of this form, there's a init method:
public Form1()
{
InitializeComponent();
his_combobox.Visible = false; //I hide everything so that I can show them when click on the radiobutton
foreach (XMLSoccerCOM.Team te in all_team) //This one for the first combobox
{
combo_team.Items.Add(te.Name.ToString());
}
foreach (XMLSoccerCOM.League le in all_league) //And the 2nd as well
{
combo_league.Items.Add(le.Name.ToString());
}
}
So looks like it's done, I just need to assign it whenever I want. In the radiobutton checkchange event I make it:
private void history_league_CheckedChanged(object sender, EventArgs e)
{
his_combobox = combo_league; // Assign the global league combobox to a local combobox.
his_odds_label.Text = "Choose the league:"; //This label is next to the his_combobox
his_odds_label.Visible = true;
his_combobox.Visible = true; //Show them if it's hidden by another radiobutton
}
private void history_team_CheckedChanged(object sender, EventArgs e)
{
his_combobox = combo_team; // Assign the global team combobox to a local combobox.
his_odds_label.Text = "Choose the team:"; //This label is next to the his_combobox
his_odds_label.Visible = true;
his_combobox.Visible = true; //Show them if it's hidden by another radiobutton
}
But it's not showing up when I Ctrl+F5, only the label shows up, the his_combobox doesn't, just like it's never be there.
Feel free to ask for more information. Thank you for your time.