Hi Guys,
New to C# and I am struggling with storing a selected item from the array of comboboxes created at the runtime. Can you please help me write the command within the button_Click event so that it calculates the sum of all selected items from the comboboxes created at the runtime. It's almost done. Thank you very much in advance
Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CourseHours
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
String[] hours = { "1", "2", "3", "4", "5", "6", "7", "8" };
private ComboBox[] hrsComboBox;
double selectedValue; //this variable should be used in the button_click event to store the selected value from hrsComboBox
double finalResult; //this variable should be used in the button_click event to add all the values selected by the user
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int count = Convert.ToInt16(comboBox1.SelectedItem.ToString());
int z=259, m=75;
hrsComboBox = new ComboBox[count];
for (int i = 0; i < count; i++)
{
hrsComboBox[i] = new ComboBox();
hrsComboBox[i].Items.AddRange(hours);
hrsComboBox[i].Location = new System.Drawing.Point(z, m);
hrsComboBox[i].Size = new Size(80, 70);
hrsComboBox[i].TabIndex = 1;
this.Controls.Add(hrsComboBox[i]);
this.ResumeLayout(false);
m += 40;
}
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}