clb = new CheckedListBox[7];
clb[0] = checkedListBox1;
clb[1] = checkedListBox3;
clb[2] = checkedListBox4;
clb[3] = checkedListBox5;
clb[4] = checkedListBox6;
clb[5] = checkedListBox7;
clb[6] = checkedListBox8;每个clb内中不固定有多少个选项.要求:算出所有clb中选项选种的组合例如:clb[0]中第1.2项被选中 其他1-6只有第1项被选种
那么就是 0000000 和1000000 这2种组合 根据对应选种index列出来
clb[0] = checkedListBox1;
clb[1] = checkedListBox3;
clb[2] = checkedListBox4;
clb[3] = checkedListBox5;
clb[4] = checkedListBox6;
clb[5] = checkedListBox7;
clb[6] = checkedListBox8;每个clb内中不固定有多少个选项.要求:算出所有clb中选项选种的组合例如:clb[0]中第1.2项被选中 其他1-6只有第1项被选种
那么就是 0000000 和1000000 这2种组合 根据对应选种index列出来
clb[0]==0,clb[1]==0,clb[2]==0,clb[3]==0,clb[4]==0,clb[5]==0,clb[6]==0,clb[7]==0,
clb[0]==1,clb[1]==0,clb[2]==0,clb[3]==0,clb[4]==0,clb[5]==0,clb[6]==0,clb[7]==0,
这2种组合
根据这个判断 clb[0].GetItemChecked(i)
也就是计算clb选种的选项所有组合如果clb[0]的第1项被选种 那么第1项的选种index值不就是0吗?
如果clb[1]的第2项被选种 那么第1项的选种index值不就是 1吗?
如果clb[2]的第3项被选种 那么第1项的选种index值不就是 3吗?
如果clb[4]的第1项被选种 那么第1项的选种index值不就是 0吗?那么这4个选种组合就是0130
如果clb[0] 再多选种第2项的话 就是1130 和0130
如果clb[0]的第1项被选种 那么第1项的选种index值不就是0吗?
如果clb[1]的第2项被选种 那么第2项的选种index值不就是 1吗?
如果clb[2]的第3项被选种 那么第3项的选种index值不就是 3吗?
如果clb[4]的第1项被选种 那么第1项的选种index值不就是 0吗?
这个应该是2 我晕死``自己都迷糊了`最后结果1120 0120
int b = 3;
int c = 3;那么这3个变量的组合有27种
既111 112 113...我要做的是从 clb[0]到clb[6]中所有选项选种的组合 根据对应的index值列出来
void GetList()
{
List<List<int>> list = new List<List<int>>();
List<int> clb0 = new List<int>(new int[] { 0, 1, 2 });//哪些项选中就加哪些项
List<int> clb1 = new List<int>(new int[] { 0, 1, 2 });
List<int> clb2 = new List<int>(new int[] { 0, 1, 2 });
list.Add(clb0);
list.Add(clb1);
list.Add(clb2);
List<string> result = new List<string>();
result.Add("");
foreach (List<int> l in list)
{
result = GetString(result, l);
}
foreach (string s in result)
this.textBox1.Text += s + "\r\n";//输出到文本框 } List<string> GetString(List<string> result,List<int> cb1)
{
List<string> temp = new List<string>();
foreach (string s in result)
{
for (int i = 0; i < cb1.Count; i++)
{
temp.Add(s + cb1[i]+" ");
}
}
return temp;
} private void button1_Click(object sender, EventArgs e)//调用
{
GetList();
}/*执行结果:
0 0 0
0 0 1
0 0 2
0 1 0
0 1 1
0 1 2
0 2 0
0 2 1
0 2 2
1 0 0
1 0 1
1 0 2
1 1 0
1 1 1
1 1 2
1 2 0
1 2 1
1 2 2
2 0 0
2 0 1
2 0 2
2 1 0
2 1 1
2 1 2
2 2 0
2 2 1
2 2 2
*/
int[] send_type = new int[6];
int[] cd= new int[6];
int[] temp = new int[6] { 0,0,0,0,0,0};
string num = ""; for (int i = 0; i < 6; i++)//计算有效checked
{
for (int j = 0; j < clb[i].Items.Count; j++)
{
if (clb[i].GetItemChecked(j))
{
cd[i] += 1;
}
}
}
for (int a0 = 0; a0 < cd[0]; a0++)
{
for (int b0 = temp[0]; b0 < clb[0].Items.Count; b0++)
{
if (clb[0].GetItemChecked(b0))
{
send_type[0] = b0;
temp[0] = b0 + 1;
b0 = clb[0].Items.Count;
}
}
for (int a1 = 0; a1 < cd[1]; a1++)
{
for (int b1 = temp[1]; b1 < clb[1].Items.Count; b1++)
{
if (clb[1].GetItemChecked(b1))
{
send_type[1] = b1;
temp[1] = b1 + 1;
b1 = clb[1].Items.Count;
}
}
for (int a2 = 0; a2 < cd[2]; a2++)
{
for (int b2 = temp[2]; b2 < clb[2].Items.Count; b2++)
{
if (clb[2].GetItemChecked(b2))
{
send_type[2] = b2;
temp[2] = b2 + 1;
b2= clb[2].Items.Count;
}
}
for (int a3 = 0; a3 < cd[3]; a3++)
{
for (int b3 = temp[3]; b3 < clb[3].Items.Count; b3++)
{
if (clb[3].GetItemChecked(b3))
{
send_type[3] = b3;
temp[3] = b3 + 1;
b3 = clb[3].Items.Count;
}
}
for (int a4 = 0; a4 < cd[4]; a4++)
{
for (int b4 = temp[4]; b4 < clb[4].Items.Count; b4++)
{
if (clb[4].GetItemChecked(b4))
{
send_type[4] = b4;
temp[4] = b4 + 1;
b4= clb[4].Items.Count;
}
}
for (int a5 = 0; a5 < cd[5]; a5++)
{
for (int b5 = temp[5]; b5 < clb[5].Items.Count; b5++)
{
if (clb[5].GetItemChecked(b5))
{
send_type[5] = b5;
temp[5] = b5 + 1;
b5 = clb[5].Items.Count;
}
} for (int ss = 0; ss< 6; ss++)
{ num += send_type[ss].ToString() + ",";
}
number_algorithm(num);//传递算法类型
num = "";
}
}
}
}
}
}