How do you hide a column in a datagrid using the .net compact framework 3.5
Solution 1
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);
Solution 2
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")
Solution 3
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!!
runxc1 Bret Ferrier
I am a Software Engineer with a passion for development. I code at work and at home when I get the chance but I also have some wonderful kids so not always. When not writing code I like getting outdoors and am a runner that also likes to cycle, snowboard, hike etc.
Updated on June 04, 2022Comments
-
runxc1 Bret Ferrier almost 2 years
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.
-
runxc1 Bret Ferrier almost 15 yearsThis would work but as I mentioned I am using a DataReader and not a DataTable
-
One-One over 12 years@DaDa anyway to make this work with List<BusinessObj>? Thanks.
-
Ben over 5 yearsIt might worth mentioning the DataGridColumnStyle
.MappingName
must be unique. Resytling requires GridColumnStyles.Clear() before Add(), or locate & modify exisiting ColStyle with the right MappingName.