Hiding Columns in datagrid

B

Bhargavan

Hi,
I am using a datagrid on a windows form. The datasource of the grid is bound
to a class array. It works just fine. But I am not sure how to hide some
columns in the grid programmatically. Any suggestions in this regard will be
greatly appreciated.
Bhargavan M
 
U

Uchiha Jax

You will want to use a datagridtable style.

DataGridTableStyle dts = new DatagirdTableStyle();
dts.MappingName = "The TYPE name of your class collection, e.g: 'ArrayList'
for an arraylist or if you are using a datatable the tablename of the
table";
DataGridTextBoxColumn textCol = new DataGridTextBoxColumn();
textCol.MappingName = "NameOfPublicProperty";
textCol.HeaderName = "Header";
dts.GridColumnStyles.Add(textCol);
this.dataGrid1.TableStyles.Add(dts);

Now the datagrid will show ONLY the columns specified in the tablestyle, all
other columns will be ignored, if you don't get the Mapping name right it
will display as normal.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top