8 Kasım 2014 Cumartesi

Bir tabControldeki seçilmiş checbox sayısının elde edilmesi

Eğer bir tabControl içinde birden fazla tabınız varsa ve bu tablardaki checkboxlardan kaç tanesinin seçilmiş olduğu bilgisine ihtiyacınız varsa aşaığdaki satırlar işinizi görecektir.

int number = 0;
foreach (TabPage tp in tabControl1.Controls)
     foreach (Control c in tp.Controls)
          if (c is CheckBox)
               if (((CheckBox)c).Checked)
                    number++;

MessageBox.Show("" + number);

Kodda ufak değişiklikler yaparak checkbox yerine istediğiniz control tipinden istediğiniz durumda olanların sayısını da elde edebilirsiniz.

Counting the number of checked checkboxes in a TabControl

If you have multiple tabs in a tab control and you want to know the total number of checked checkboxes in this tab the following lines will be helpful:

int number = 0;
foreach (TabPage tp in tabControl1.Controls)
     foreach (Control c in tp.Controls)
          if (c is CheckBox)
               if (((CheckBox)c).Checked)
                    number++;

MessageBox.Show("" + number);

You may change the code easily to get the number of non-null textboxes and so on..