DataGrid Hide columns if all row values are null

MattNorman

Well-known member
Joined
May 22, 2021
Messages
98
Programming Experience
1-3
I have a model that contains a lot of fields that are bound to my data grid.

A lot of those fields may have null values depending on skills that each user has assigned to them. (99 possible but typically will only be up to 20)

Is there a way that I can set the visibility of a text column if all row values for that column are null/empty?

The only way I can think of is to have a bunch of visibility properties in my view model, set those whenever the data is refreshed and bind them to the text columns visibility property.

This should work but seems a bit of a messy way of doing it.

Does anyone have any better ways of doing this?
 
That approach seems to be as good as any considering that this is not normally how the grid view is used.
 
The title says "DataGridView", which is a control specific to Windows Forms, but you have posted this thread in the WPF forum. Are you actually using a DataGrid? The answer probably doesn't change the solution but it's good to be accurate, just in case.
 
The title says "DataGridView", which is a control specific to Windows Forms, but you have posted this thread in the WPF forum. Are you actually using a DataGrid? The answer probably doesn't change the solution but it's good to be accurate, just in case.
Yes sorry it is a DataGrid. Only recently switched over to WPF
 
Why aren't you generating your view instead of being shabby by setting visibility? I will let you research how to change your xaml code by re-rendering your apps ui. As to explain would be very lengthy, and is a separate issue to your question.

To answer, yes, like most parts of most controls in wpf, they can be partially visually hidden but not the recommended approach for what you are doing. dataGrid.Columns[int here].Visibility = Visibility.Hidden;

I'd ponder on your design-flow a little more if I was you.
 
Back
Top Bottom