Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 514
runxc1 Bret Ferrier Avatar asked Dec 04 '22 15:12

runxc1 Bret Ferrier


2 Answers

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);
like image 139
NET Experts Avatar answered Dec 06 '22 04:12

NET Experts


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")
like image 23
Iralda Mitro Avatar answered Dec 06 '22 04:12

Iralda Mitro