string分割成数组,且ListBox根据数组添加item,且对应ListBox取值判断及数组循环

1、string分割成数组

public static string Term_Field = "Folk,Age,Kultur,Marriage,Sex,Visage,WorkLength,Employee,Business,Laborage,Branch,Duthcall,School,Speciality,Pact_Y,BeAware,City";

        public static string Term_Value = "民族类别,年龄,文化程度,婚姻,性别,政治面貌,工龄,员工状态,职务类别,工资类别,部门类别,职称类别,毕业学校,主修专业,合同年限,籍贯所在省,籍贯所在市";
        public static string[] A_Field = Term_Field.Split(Convert.ToChar(','));
        public static string[] A_Value = Term_Value.Split(Convert.ToChar(','));



2、ListBox根据数组添加item

 listBox1.Items.Clear();
            for (int i = 0; i < A_Value.Length; i++)

            {
                listBox1.Items.Add("按" + A_Value[i] + "统计");

            }


3、对应ListBox取值判断及数组循环

           if (listBox1.SelectedIndex==-1)  //判断是否选择了listBox明细项
            {
                MessageBox.Show("请选择具体的项目!");
            }
            else
            {
                string sql = DataClass.MyMeans.AllSql;
                string values = dataGridView1.CurrentRow.Cells[0].Value.ToString();              
                string listitem = listBox1.SelectedItem.ToString();
                int index = listitem.IndexOf('统');             
                for (int i = 0; i < A_Value.Length; i++)
                {
                    if (listitem.Substring(1, index-1) == A_Value[i])
                    {                   
                        string field = A_Field[i].ToString();
                        sql = sql + " where " + field + " = '" + values+"'";                 
                        dataGridView2.DataSource = DataClass.MyMeans.ExecuteDatatable(sql, CommandType.Text);
                    }
                }
            }


你可能感兴趣的:(C#.net,数组,listBox)