在一数据库里通过以下语句增加纪录
sql = "INSERT INTO Records(编号, 名称, 位置) VALUES ('" + textBox2.Text + "', '" + textBox1.Text + "', '" + comboBox2.Text + comboBox3.Text + comboBox4.Text + "' ) ";
现在要通过下面的datagridview将存储的内容显示出来
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            textBox1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            textBox2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
            comboBox2.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            comboBox3.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            comboBox4.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
        }
请问怎样将cells[2]里的位置数据分离出来 分别显示在combbox2、3、4中
数据格式是:第X行第Y列第Z层

解决方案 »

  1.   


    void Main()
    {
      string str="第X行第Y列第Z层"; foreach(Match m in Regex.Matches(str,@"第[^第]*"))
    {
    Console.WriteLine(m.Value);
    }
    }/*
    第X行
    第Y列
    第Z层
    */剩下的赋值操作  你懂的
      

  2.   

            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                textBox1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                textBox2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                string str = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                foreach (Match m in Regex.Matches(str, @"第[^第]*"))
                {
                    comboBox2.Text = m.ToString();
                    comboBox3.Text = m.ToString();
                    comboBox4.Text = m.ToString();
                }
            }
    怎样才能将每次循环的值分别赋给combobox234呢
      

  3.   

     
    private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                textBox1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                textBox2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                string str = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                 MatchCollection mc= Regex.Matches(str,"第[^第]*");

                    comboBox2.Text = mc[0].Groups[1].Value
                    comboBox3.Text =mc[1].Groups[1].Value
                    comboBox4.Text = mc[2].Groups[1].Value
    //如果comboBox的名字比较规律  可以利用 for循环来添加
            }  MatchCollection mc= Regex.Matches(str,"第[^第]*");
    mc[0].Groups[1].Value
      

  4.   

    不需要.groups
            private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
            {
                textBox1.Text = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
                textBox2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                string str = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                MatchCollection mc= Regex.Matches(str,"第[^第]*");
                comboBox2.Text = mc[0].Value;
                comboBox3.Text = mc[1].Value;
                comboBox4.Text = mc[2].Value;
            }