C# 如何删除或隐藏数据表中的特定列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13416761/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 08:29:48  来源:igfitidea点击:
How to remove or hide particular column in a datatable?
提问by Bharathi
I am using C#. I want to hide or remove the column from DataTable or DataSet . I attach my partial code:
我正在使用 C#。我想隐藏或删除 DataTable 或 DataSet 中的列。我附上我的部分代码:
DataTable dt = new DataTable();
DataView dv = new DataView();
dv = (DataView)Session["map_hi"];
dt = dv.ToTable();
dt.Columns[0].ColumnMapping = MappingType.Hidden;
dt.AcceptChanges();
采纳答案by Pranay Rana
try this
尝试这个
   DataTable t;
   t.Columns.Remove("columnName");
   t.Columns.RemoveAt(columnIndex);
回答by KaeL
Use Visibleproperty to hide the specific column:
使用Visible属性隐藏特定列:
dt.Columns[0].Visible= false;
回答by Rakesh Yking
To hide and show try this:
要隐藏和显示试试这个:
For hiding:
对于隐藏:
dt.Columns[ColumnIndex].Visible = false; 
or:
或者:
dt.Columns["ColumnName"].Visible = false;
For showing:
用于展示:
dt.Columns[ColumnIndex].Visible = true;  
or:
或者:
dt.Columns["ColumnName"].Visible = true;

