我从数据库中提出两个字段,绑顶到datagrid中。在datagrid中第一列不显示,但是数据必须存在。
请教高手该如何解决?

解决方案 »

  1.   

    以编程方式隐藏数据网格中的列
    在窗体的声明区域中声明 DataGridTableStyle 类的新实例。将 DataGridTableStyle 的 MappingName 属性设置为希望应用样式的数据源中的表。下面的代码示例使用 DataGrid.DataMember 属性(假定已经设置了它)。向数据网格的表样式集合中添加新的 DataGridTableStyle 对象。通过将列的 Width 属性设置为 0,并指定要隐藏的列的列索引来隐藏列。 
    // Declare a new DataGridTableStyle in the
    // declarations area of your form.
    DataGridTableStyle ts = new DataGridTableStyle();private void hideColumn()
    {
       // Set the DataGridTableStyle.MappingName property
       // to the table in the data source to map to.
       ts.MappingName = dataGrid1.DataMember;   // Add it to the datagrid's TableStyles collection
       dataGrid1.TableStyles.Add(ts);   // Hide the first column (index 0)
       dataGrid1.TableStyles[0].GridColumnStyles[0].Width = 0;
    }
      

  2.   

    是ID列么?不用不显示,可以把值放到DataKey里,也可以自定义列