![](/img/trans.png)
[英]How do you find the number of rows in a DataGrid using .net compact framework?
[英]How do you hide a column in a datagrid using the .net compact framework 3.5
我有一個使用DataReader作為其數據源的DataGrid。 我想隱藏數據網格的第一列。 我正在使用.net緊湊框架3.5。 我可以找到Windows窗體的示例,但api已經改變,它們不起作用。
您可以將列樣式寬度設置為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);
無論如何,在分配數據源之前,請隱藏您不想顯示的列:
ds.Tables("dtRecords").Columns("ID").ColumnMapping = MappingType.Hidden
Datagrid1.datasource = ds.Tables("dtRecords")
正如Henk所說,我剛剛使用DataGridTableStyle和GridColumnStyles解決了這個問題。 但是,我也將GridColumnStyle中的Width屬性賦值為-1。
而且,它的作品!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.