DataTable
I have been Googling all over to try and find a way to set a certain column to hidden. It seems the only way is to hide it in the DataGrid (Working in windows Forms), but I would like to be able to set a Column as Hidden in the DataTable and have the DagaGrid hide that column.
I have tried this:
datatable.Columns[0].ColumnMapping = MappingType.Hidden;
But that does not work.
Is there a way to create one's own Custom DataTable, inherited from the original DataTable, so one would be able to specify a column to be hidden. I'm thinking you might need a custom datagrid as well?
Summary:
Developer must be able to specify which column should be hidden.
Datagrid should be able to tell which columns to hide.
I'm not to good with custom controls, if someone could help it would be much appreciated.
Thanks
[EDIT]: For some reason the post keeps going into one line...
NeCroFirePosted Feb 4, 2009, 2:05 AM
You set your Column mapping to Hidden when you declare your DataTable's columns... like this:
datatable1.Columns.Add(new System.Data.DataColumn("ClientID", typeof(String), "", MappingType.Hidden))
Now when you set your DataGrid's DataSource equal to datatable1 the columns with the mapping type will not be shown.
It was actually so simple, but I had no idea that you could add extra properties to your new column. I figured this out by accident really... ;)
yev fesPosted Feb 3, 2009, 12:02 PM
I dont entirely understand your question, but the way I set only certian columns to be displayed in a DataGrid is using DataGridTableStyles:
dataGridTableStyle1 = new DataGridTableStyle();
dataGridTableStyle1.MappingName = this.someDataSet.SomeTable.TableName;
and then you can add columns to the styles list:
DataColumn c = new DataColumn();
dataGridTableStyle1.GridColumnStyles.Add(c);
NeCroFirePosted Jan 20, 2009, 2:16 AM
DataTableColumns.Add(new System.Data.DataColumn("ClientID", typeof(String), "", MappingType.Hidden));
The columns with the Mapping Type:Hidden will not be shown on the datagrid.
Posted Jan 19, 2009, 1:00 PM
First of all i am a begineer.....but have worked with data grid....i could not get ur point exactly....anyway....u dont have to hide a column from displayin...rather select only the columns u want to display using a select statement before and display it......
Hope it helps.........