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?
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.
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.
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With