Check the checked property of the checkbox (==true) and the selectedindex of the combox (>-1), e.g.
if (checkBox1.Checked && comboBox1.SelectedIndex > -1) {
// do something
}
refer:
1.
CheckBox.Checked Property[
^]
2.
ComboBox.SelectedIndex Property[
^]
+++++++++++[round 2]+++++++++
You can create checkboxes and comboxes and placed them in separate List objects. Then insert a button on your form, in the click event handler of this button, loop through both list objects and check the condition for compliance. Try this:
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 WindowsFormsApplicationCS
{
public partial class Form16 : Form
{
List<CheckBox> checkboxList = new List<CheckBox>();
List<ComboBox> comboboxList = new List<ComboBox>();
public Form16()
{
InitializeComponent();
}
private void Form16_Load(object sender, EventArgs e)
{
int j = 1;
int k = 1;
for (int i = 1; i <= 25; i++)
{
CheckBox chkBox = new CheckBox();
chkBox.Tag = i.ToString();
chkBox.Name = "Slot" + i;
if (i <= 9)
{ chkBox.Text = "Slot0" + i; }
else
{ chkBox.Text = "Slot" + i; }
if (i <= 13)
{ chkBox.Location = new Point(10, j * 20);}
else
{ chkBox.Location = new Point(210, k * 20); }
this.Controls.Add(chkBox);
checkboxList.Add(chkBox);
ComboBox cmbBox = new ComboBox();
cmbBox.Tag = i.ToString();
cmbBox.Name = "Mode" + i;
cmbBox.Items.Add("REGULAR STUDENT");
cmbBox.Items.Add("VOCATIONAL STUDENT");
cmbBox.AutoSize = true;
if (i <= 13)
{ cmbBox.Location = new Point(70, j * 20); j++; }
else { cmbBox.Location = new Point(270, k * 20); k++; }
this.Controls.Add(cmbBox);
comboboxList.Add(cmbBox);
}
}
private void button1_Click(object sender, EventArgs e)
{
for (int i = 0; i < checkboxList.Count; i++)
{
if (checkboxList[i].Checked && comboboxList[i].SelectedIndex == -1)
{
MessageBox.Show("You have checked "+ checkboxList[i].Name +" but forget to select " + comboboxList[i].Name);
}
}
}
}
}