How to hide column in datagrid using .net compact framework 3.5

I have a DataGrid that uses a DataReader as a data source. I want to hide the first column of a datagrid. I am using .net compact framework 3.5. I can find examples for Windows forms, but the api has changed so much that they do not work.

+4
source share
3 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); 
+12
source

In any case, assign a data source to you, hide the columns that you do not want to show:

 ds.Tables("dtRecords").Columns("ID").ColumnMapping = MappingType.Hidden Datagrid1.datasource = ds.Tables("dtRecords") 
+3
source

I just solved this problem using DataGridTableStyle and GridColumnStyles, as Henk says. But I also set the Width property of GridColumnStyle to -1. A.

And it works!

+2
source

All Articles