如何使用.net compact framework 3.5在数据网格中隐藏列

我有一个使用DataReader作为其数据源的DataGrid。 我想隐藏数据网格的第一列。 我正在使用.net紧凑框架3.5。 我可以找到Windows窗体的示例,但api已经改变,它们不起作用。

您可以将列样式宽度设置为0-1

 DataGridTableStyle ts = new DataGridTableStyle(); ts.MappingName = "Order"; // Order date column style DataGridColumnStyle cust_id = new DataGridTextBoxColumn(); cust_id.MappingName = "cust_id"; cust_id.HeaderText = "ID"; //Hide Customer ID cust_id.Width = -1; ts.GridColumnStyles.Add(cust_id); // Shipping name column style DataGridColumnStyle cust_name = new DataGridTextBoxColumn(); cust_name.MappingName = "cust_name"; cust_name.HeaderText = "Customer"; cust_name.Width = 500; ts.GridColumnStyles.Add(cust_name); GridView1.TableStyles.Add(ts); 

无论如何,在分配数据源之前,请隐藏您不想显示的列:

 ds.Tables("dtRecords").Columns("ID").ColumnMapping = MappingType.Hidden Datagrid1.datasource = ds.Tables("dtRecords") 

正如Henk所说,我刚刚使用DataGridTableStyle和GridColumnStyles解决了这个问题。 但是,我也将GridColumnStyle中的Width属性赋值为-1。

而且,它的工作原理!!