Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to hide a specific column in a DataGrid when AutoGenerateColumns=True?

Tags:

wpf

xaml

datagrid

I have a WPF 4.0 DataGrid that is bound to a DataTable using AutoGenerateColumns=True. The columns are dynamic, however I know there is always going to be a column named ID and I would like to hide this column. Is there a way I can do this?

like image 217
Rachel Avatar asked Oct 22 '10 19:10

Rachel


People also ask

How do I hide columns in data grid?

To hide a column in the DataGrid programmatically DataMember property, which it assumes is already set. Add the new DataGridTableStyle object to the datagrid's table styles collection. Hide the column by setting its Width property to 0, specifying the column index of the column to hide.

How do I filter DataGrid?

To filter items in a DataGridAdd a handler for the CollectionViewSource. Filter event. In the Filter event handler, define the filtering logic. The filter will be applied every time the view is refreshed.

How do I hide a column in ASPX?

The way to hide a column in a DataBound GridView is to trap the RowCreated Event and set a Cell inside the column of the row to Visible = false. Nice!


1 Answers

in your datagrid, subscribe for the AutoGeneratingColumn event, the event args (DataGridAutoGeneratingColumnEventArgs) has the column name and a "Cancel", if the column name is ID then set Cancel = true. should do the trick.

like image 68
Alex Lo Avatar answered Sep 28 '22 01:09

Alex Lo