C# 如何使用.net compact framework 3.5在datagrid中隐藏列
我有一个DataGrid,它使用DataReader作为数据源。我想隐藏datagrid的第一列。我使用的是.net compact framework 3.5。我可以找到windows窗体的示例,但api的变化太大,无法正常工作。无论如何,在您 分配数据源,隐藏不想显示的列:C# 如何使用.net compact framework 3.5在datagrid中隐藏列,c#,.net,datagrid,windows-mobile,compact-framework,C#,.net,Datagrid,Windows Mobile,Compact Framework,我有一个DataGrid,它使用DataReader作为数据源。我想隐藏datagrid的第一列。我使用的是.net compact framework 3.5。我可以找到windows窗体的示例,但api的变化太大,无法正常工作。无论如何,在您 分配数据源,隐藏不想显示的列: ds.Tables("dtRecords").Columns("ID").ColumnMapping = MappingType.Hidden Datagrid1.datasource = ds.Tables("dtR
ds.Tables("dtRecords").Columns("ID").ColumnMapping = MappingType.Hidden
Datagrid1.datasource = ds.Tables("dtRecords")
正如Henk所说,我刚刚使用DataGridTableStyle和GridColumnStyles解决了这个问题。但是,我还将GridColumnStyle中的Width属性指定给了-1
而且,它是有效的 您可以将列样式宽度设置为
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);
这会起作用,但正如我提到的,我使用的是数据读取器,而不是DataTable@DaDa无论如何,让这个列表工作?谢谢。值得一提的是DataGridColumnStyle
。MappingName
必须是唯一的。重新排序需要在添加()之前使用GridColumnStyles.Clear(),或者使用正确的映射名称查找和修改现有的ColStyle。