记录查询条件推荐考虑用本地xml文件

解决方案 »

  1.   

    好像用vb2005可以实现 c#不行
      

  2.   

    foreach (Control cr in this.Controls)
                {
                    if (cr.Name == ControName)
                    {
                        
                    }
                }
    这样应该能够找到相应的控件,GetType()可以获得控件的类型,属性设置只能根据属性的类型去分配了。呵呵,关注中!
      

  3.   

    dataset数据集自己写方法填。
                DataSet ds = new DataSet();
                ds = Func.DBbind("select ControlName,ControlProperty from table");
                foreach (Control c in this.Controls)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (c.Name == ds.Tables[0].Rows[i]["ControlName"].ToString())
                        {
                            c.Text = ds.Tables[0].Rows[i]["ControlProperty"].ToString();
                            ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                            break;
                        }
                    }
                }
      

  4.   

    alldj(灵山妖姬),我的界面控件中不只有Text屬性,還有其他屬性保存,也不僅僅只有TextBox控件??
      

  5.   

    TextBox[] a= new TextBox[20];
    a[0]=new TextBox();
      

  6.   

    System.Reflection.PropertyInfo pi = t.GetType().GetProperty(name);
    pi.SetValue(control, value, null);name / value 就是你保存的属性名称/值, control就是要设置的控件对象
      

  7.   

    或者:using System.ComponentModel;......foreach(Control control in allControls)
    {
        foreach(PropertyDescriptor pd in TypeDescriptor.GetProperties(control))
        {
    if(hasValue(pd.Name))
             {
        pd.SetValue(getValue(pd.Name));
    }
        }
    }// allControls / hasValue() / getValue() 你自己定义
      

  8.   

    System.Reflection.PropertyInfo pi = t.GetType().GetProperty(name);
    pi.SetValue(control, value, null);name / value 就是你保存的属性名称/值, control就是要设置的控件对象t是什么東西呢?我想用反射應該更好吧???????
      

  9.   

    写错了 
    System.Reflection.PropertyInfo pi = control.GetType().GetProperty(name);
      

  10.   

    DataSet ds = new DataSet();
                ds = Func.DBbind("select ControlName,ControlProperty from table");
                foreach (Control c in this.Controls)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        if (c.Name == ds.Tables[0].Rows[i]["ControlName"].ToString())
                        {
                            System.Reflection.PropertyInfo pi = c.GetType().GetProperty(ds.Tables[0].Rows[i]["ControlProperty"].ToString());
                            pi.SetValue(c,"value", null);
                            ds.Tables[0].Rows.Remove(ds.Tables[0].Rows[i]);
                            break;
                        }
                    }
                }
      

  11.   

    可以用xml的作为配置文件
    同时要知道有些控件的属性是只读的
      

  12.   

    楼上的有道理;
    这种用xml的作为配置文件保存到本地,然后需亚时加载进来。比较合理!
      

  13.   

    楼上两位正解
    大家都没考虑到容器的问题
    所以XML比较好
      

  14.   

    控件.DataBindings.Add();好好去研究研究
      

  15.   

    .net FrameWork帮助里还有现成的例子
    ms-help://MS.NETFrameworkSDKv1.1.CHS/cpref/html/frlrfsystemwindowsformscontrolclassdatabindingstopic.htm