在WINFORM中想实现个功能:
把用户填写的内容动态的添加到一个表格里,但是表格里的东西不全往数据库添加,所以就不想用DATATABLE了,而是动态生成一个表格,里面有用户添加的东西,然后在程序中再用NewRow()来添加DATATABLE中的行(这个DATATABLE不在界面中显示出来),不知道各位是怎么实现这个功能的?比如用户添加性别:
在界面上生成是男或女,而在DATATABLE中生成的确实M或F~~~

解决方案 »

  1.   

    可以用datagridstyle更改、填加datagrid列,可以加入不和数据库联系的列。
      

  2.   

    可以用datagridstyle更改、填加datagrid列,可以加入不和数据库联系的列。
      

  3.   

    楼上的兄弟能详细说说吗?该怎么把一组数据手动添加到DATAGRID中呢?
      

  4.   

    System.Windows.Forms.DataGridTableStyle style = new DataGridTableStyle();
    System.Windows.Forms.DataGridTextBoxColumn a = new DataGridTextBoxColumn();
    System.Windows.Forms.DataGridTextBoxColumn b = new DataGridTextBoxColumn();
    System.Windows.Forms.DataGridBoolColumn c = new DataGridBoolColumn(); style.MappingName = "aaa";
    style.GridColumnStyles.Add(a);
    style.GridColumnStyles.Add(b);
    style.GridColumnStyles.Add(c); a.Width = 100;
    a.MappingName = "1";
    a.HeaderText = "第一列";
    a.TextBox.BackColor = Color.Blue; b.Width = 100;
    b.MappingName = "2";
    b.HeaderText = "第二列";
    b.TextBox.BackColor = Color.Red; c.Width = 100;
    c.MappingName = "3";
    c.HeaderText = "第三列"; this.dataGrid1.TableStyles.Add(style);
      

  5.   

    我是这么写的~~~==============================
    private void data_bind_front(DataGrid dg,string Depots,string Receive,string Suppliers,string Brands,string Models,string Colors,string Imei_num)
    {
    DataTable tb = new DataTable(); DataGridTableStyle ts = new DataGridTableStyle();
    ts.MappingName = "new_imei";
    DataGridTextBoxColumn depots_name = new DataGridTextBoxColumn();
    DataGridTextBoxColumn receive_type = new DataGridTextBoxColumn();
    DataGridTextBoxColumn suppliers_name = new DataGridTextBoxColumn();
    DataGridTextBoxColumn brands = new DataGridTextBoxColumn();
    DataGridTextBoxColumn models = new DataGridTextBoxColumn();
    DataGridTextBoxColumn colors = new DataGridTextBoxColumn();
    DataGridTextBoxColumn imei_num = new DataGridTextBoxColumn(); depots_name.HeaderText = "库房";
    receive_type.HeaderText = "入库类型";
    suppliers_name.HeaderText = "供应商";
    brands.HeaderText = "品牌";
    models.HeaderText = "型号";
    colors.HeaderText = "颜色";
    imei_num.HeaderText = "串号"; depots_name.MappingName = "depots_name";
    receive_type.MappingName = "receive_type";
    suppliers_name.MappingName = "suppliers_name";
    brands.MappingName = "brands";
    models.MappingName = "models";
    colors.MappingName = "colors";
    imei_num.MappingName = "imei_num"; depots_name.MappingName = Depots;
    receive_type.MappingName = Receive;
    suppliers_name.MappingName = Suppliers;
    brands.MappingName = Brands;
    models.MappingName = Models;
    colors.MappingName = Colors;
    imei_num.MappingName = Imei_num; ts.GridColumnStyles.Add(depots_name);
    ts.GridColumnStyles.Add(receive_type);
    ts.GridColumnStyles.Add(suppliers_name);
    ts.GridColumnStyles.Add(brands);
    ts.GridColumnStyles.Add(models);
    ts.GridColumnStyles.Add(colors);
    ts.GridColumnStyles.Add(imei_num); dg.TableStyles.Add(ts);
    }=============================
    调用上面的方法
    data_bind_front(this.dg_imei_list,"depot","receive","suppliers","brands","models","red","111111111111111");