PDA

View Full Version : نحوه گرفتن مقادیر تیک خورده چندین CheckListBox با استفاده از یک حلقه تکرار



mrmaleki
پنج شنبه 12 تیر 1393, 17:51 عصر
سلام
من 8 تا CheckListBox تو یرنامم دارم که میخوامم مقادیر خورده اونارو به یک آرایه با نام جدا تخصیص بدم تو کد زیر میتونم با یک حلقه تکرار این کارو انجام بدم و به جای اونکه 8 بار یک آرایه int تعریف کنم که فقط تو شماره آخر اسمشون با هم اختلاف دارن با یک for این کارو انجام بدم؟

int[] ChLi1 = checkedListBox1.CheckedIndices.Cast<int>().ToArray();
int[] ChLi2 = checkedListBox2.CheckedIndices.Cast<int>().ToArray();
int[] ChLi3 = checkedListBox3.CheckedIndices.Cast<int>().ToArray();
int[] ChLi4 = checkedListBox4.CheckedIndices.Cast<int>().ToArray();
int[] ChLi5 = checkedListBox5.CheckedIndices.Cast<int>().ToArray();
int[] ChLi6 = checkedListBox6.CheckedIndices.Cast<int>().ToArray();
int[] ChLi7 = checkedListBox7.CheckedIndices.Cast<int>().ToArray();
int[] ChLi8 = checkedListBox8.CheckedIndices.Cast<int>().ToArray();


مثلا تو کد زیر مجبور شدم برای غیر فعال کردن اجزای فرم مجیور شدم اجزایی رو که فقط یک شماره با هم اختلاف دارنو پشت سر هم بنویسم


private void DisableTabControl2_Options()
{
checkedListBox1.Enabled = false;
checkedListBox2.Enabled = false;
checkedListBox3.Enabled = false;
checkedListBox4.Enabled = false;
checkedListBox5.Enabled = false;
checkedListBox6.Enabled = false;
checkedListBox7.Enabled = false;
checkedListBox8.Enabled = false;
label2.Enabled = false;
label3.Enabled = false;
label4.Enabled = false;
label5.Enabled = false;
label6.Enabled = false;
label7.Enabled = false;
label8.Enabled = false;
label9.Enabled = false;


this.MainForm.checkBox1.Enabled = true;
this.MainForm.checkBox2.Enabled = true;
this.MainForm.checkBox3.Enabled = true;
this.MainForm.checkBox4.Enabled = true;
this.MainForm.checkBox5.Enabled = true;
this.MainForm.checkBox6.Enabled = true;
this.MainForm.checkBox7.Enabled = true;
this.MainForm.checkBox8.Enabled = true;


Settings.Default.CheckedListBoxStatus = false;
}

forodo007
جمعه 13 تیر 1393, 00:59 صبح
salam doste aziz ye araye tarif kon bad az hasiyate valu estefad
ke kon tavajoh dashte bash ke cheked list box
casting koni agar mesal khasti ta vasat bezaram
khaiyete checked dara , bayad az kease data row an ra