I have a DataSet similar to the one below:
ID Name Data1 Data2
1 MM X 1000
2 ST Y 1000
3 EC Z 1000
4 JT T 1000
I display this DataSet in a DataGridView by binding the DataSet. What I would like to do is set the visibility of the Data2 column based on if all the data is similar or not.
So in the above example, I would want to hide the Data2 column because the data represented is common to all elements in the DataSet. But if any of the elements had a unique entry for that column, I would want the column to be visible.
Is there a way to do this without iterating over the DataSet? I prefer not to iterate as my DataSets are quite large and I want to perform this check for multiple columns.
You can use some LINQ to check to see how many distinct values you have in that column:
If there is more than 1 distinct value, then you know that not all of the values are equal.