S
svein.erik.storkas
I'm creating an application where the user first selects a number from
a combobox. Based on his choice of number, ComboBoxes and buttons are
to be created (at runtime of course).
Let's say that the ComboBox is to be named cboTeam and the index number
(cboTeam1, cboTeam2 ...) It is also to be attached inside a specific
tabpage. How can I do this?
Some code:
//The button that gets the number the user choose:
private void cmdGenerateInputBoxes_Click(object sender, EventArgs e)
{
ReadXmlAndFillCombo( (string)cboNumberOfTeams.SelectedItem
);
}
//This is where I want to add x number of comboboxes:
public void ReadXmlAndFillCombo(string number)
{
int numberOfTeams = int.Parse(number);
//Read xml and fill the combobox(es)
fs = new FileStream(path, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite);
xmldoc = new XmlDocument();
xmldoc.Load(fs);
for (int i = 0; i <= numberOfTeams; i++)
{ //I know this is wrong, but you get the idea..
ComboBox cboTeam = new ComboBox();
this.Controls.Add(cboTeam);
this.tabNewCup.Controls.Add(cboTeam);
cboTeam.FormattingEnabled = true;
cboTeam.Location = new System.Drawing.Point(220, 424);
cboTeam.Name = "cboTeam";
cboTeam.Size = new System.Drawing.Size(121, 21);
cboTeam.TabIndex = 0;
cboTeam.Visible = true;
}
xmlnode = xmldoc.SelectNodes("(//spain/name)");
foreach (XmlNode node in xmlnode)
{
cboTeams.Items.Add(node.InnerText);
}
}
Hope someone can help me
a combobox. Based on his choice of number, ComboBoxes and buttons are
to be created (at runtime of course).
Let's say that the ComboBox is to be named cboTeam and the index number
(cboTeam1, cboTeam2 ...) It is also to be attached inside a specific
tabpage. How can I do this?
Some code:
//The button that gets the number the user choose:
private void cmdGenerateInputBoxes_Click(object sender, EventArgs e)
{
ReadXmlAndFillCombo( (string)cboNumberOfTeams.SelectedItem
);
}
//This is where I want to add x number of comboboxes:
public void ReadXmlAndFillCombo(string number)
{
int numberOfTeams = int.Parse(number);
//Read xml and fill the combobox(es)
fs = new FileStream(path, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite);
xmldoc = new XmlDocument();
xmldoc.Load(fs);
for (int i = 0; i <= numberOfTeams; i++)
{ //I know this is wrong, but you get the idea..
ComboBox cboTeam = new ComboBox();
this.Controls.Add(cboTeam);
this.tabNewCup.Controls.Add(cboTeam);
cboTeam.FormattingEnabled = true;
cboTeam.Location = new System.Drawing.Point(220, 424);
cboTeam.Name = "cboTeam";
cboTeam.Size = new System.Drawing.Size(121, 21);
cboTeam.TabIndex = 0;
cboTeam.Visible = true;
}
xmlnode = xmldoc.SelectNodes("(//spain/name)");
foreach (XmlNode node in xmlnode)
{
cboTeams.Items.Add(node.InnerText);
}
}
Hope someone can help me