DataTable dtl = new DataTable();
            dtl.Columns.Add("id");
            dtl.Columns.Add("name");
            DataRow r = dtl.NewRow();
            r[0] = 1;
            r[1] = "a";
            dtl.Rows.Add(r);
            r = dtl.NewRow();
            r[0] = 2;
            r[1] = "b";
            dtl.Rows.Add(r);
            r = dtl.NewRow();
            r[0] = 3;
            r[1] = "c";
            dtl.Rows.Add(r);            Hashtable ht = new Hashtable();
            foreach (Control ctl in Info_groupBox.Controls)
            {
                if (ctl is TextBox || ctl is RichTextBox)
                {
                    //ctl.Text = reader[col].ToString();
                    //col++;
                    ht.Add(ctl.TabIndex.ToString(), ctl);
                }
            }
            //...
            foreach(DataRow row in dtl.Rows)
            {
                TextBox ctl = ht[row[0]] as TextBox;
                if (ctl != null)
                {
                    ctl.Text = row[1].ToString();
                }
            }
大概思路,设置好tabindex,然后遍历Info_groupBox,放到Hashtable中

解决方案 »

  1.   

    这么说 groupbox中的控件是安照hash算法排的吗?
      

  2.   

    楼主仔细看下代码,是重新构造了个Hashtable 来记录tabindex和控件的对应关系
      

  3.   

    顶也顶碗了,fellowcheng 说的不错,楼主你要谢谢 fellowcheng,我替你谢谢了
      

  4.   

    直接设置textbox的tag值为 列名 ,然后直接用ctl.Text = reader[ctl.Tag.tostring()].ToString(); 
      

  5.   

    顶上楼的。
    把textbox的tag设置为列名,用列名(tag)索引。