C# 如何使用 .net compact framework 3.5 在数据网格中隐藏列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/849330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you hide a column in a datagrid using the .net compact framework 3.5
提问by runxc1 Bret Ferrier
I have a DataGrid that is using a DataReader as its datasource. I want to hide the first column of the datagrid. I am using the .net compact framework 3.5. I can find examples for windows forms but the api is changed enough that they don't work.
我有一个使用 DataReader 作为其数据源的 DataGrid。我想隐藏数据网格的第一列。我正在使用 .net 紧凑型框架 3.5。我可以找到 Windows 窗体的示例,但是 api 更改得足够多,以至于它们不起作用。
采纳答案by NET Experts
You can set the column style width to 0
or -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);
回答by Iralda Mitro
In any event, before you assign the datasource, hide the columns you do not want to show:
无论如何,在分配数据源之前,隐藏您不想显示的列:
ds.Tables("dtRecords").Columns("ID").ColumnMapping = MappingType.Hidden
Datagrid1.datasource = ds.Tables("dtRecords")
回答by Iralda Mitro
I have just solved this problem using DataGridTableStyle and GridColumnStyles as Henk says. But, I have, also, assigned the Width property, in the GridColumnStyle, to -1.
正如 Henk 所说,我刚刚使用 DataGridTableStyle 和 GridColumnStyles 解决了这个问题。但是,我也将 GridColumnStyle 中的 Width 属性指定为 -1。
And, it works!!
而且,它有效!!