![](/img/trans.png)
[英]How do you find the number of rows in a DataGrid using .net compact framework?
[英]How do you hide a column in a datagrid using the .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。
而且,它的作品!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.