Hi there, I have gotten the code to work so that when I press the button, "Add More", it adds more combo boxes to the form with the names dayBox1, dayBox2, and so on.
This is the code for that:
private void addMoreBtn_Click(object sender, EventArgs e)
{
//Keep track of how many dayBoxes we have
howMany++;
//Make a new instance of ComboBox
ComboBox dayBox = new System.Windows.Forms.ComboBox();
//Make a new instance of Point to set the location
dayBox.Location = new System.Drawing.Point(Left, Top);
dayBox.Left = 13;
dayBox.Top = 75 + dayLastTop;
//Set the name of the box to dayBoxWhateverNumberBoxItIs
dayBox.Name = "dayBox" + howMany.ToString();
//The TabIndex = the number of the box
dayBox.TabIndex = howMany;
//Make it visible
dayBox.Visible = true;
//Set the default text
dayBox.Text = "Pick One";
//Copy the items of the original dayBox to the new dayBox
for (int i = 0; i < dayBoxO.Items.Count; i++)
{
dayBox.Items.Add(dayBoxO.Items[i]);
}
//Add the control to the form
this.Controls.Add(dayBox);
//The location of the last box's top with padding
dayLastTop = dayBox.Top - 49;
}
What is the best way to print the selected member of the boxes added with the button event?
The way I was printing the information I wanted to a file before was like this (from only one box):
public void saveToFile()
{
FileInfo t = new FileInfo("Workout Log.txt");
StreamWriter Tex = t.CreateText();
Tex.WriteLine("---------------Workout Buddy Log---------------");
Tex.WriteLine("------------------- " + DateTime.Now.ToShortDateString() + " ------------------");
Tex.Write(Tex.NewLine);
if (dayBoxO.Text != "Pick One")
{
Tex.WriteLine("Day: " + dayBoxO.Text);
}
else
{
Tex.WriteLine("Day: N/A");
}
}
I want to be able to do this for every box, each on a new line. So, it would be like: Day: (the text of box1) Day: (the text of box2) Day: (the text of box3) and so on... Thanks!