How do you hide a column in a datagrid using the .net compact framework 3.5

对着背影说爱祢 提交于 2019-12-04 12:56:20
NET Experts

You can set the column style width to 0 or -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);

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")

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.

And, it works!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!