tags:

views:

82

answers:

4

I've got ~20 columns in a grid each of which can be shown or hidden via a checkbox in another dialog.

The visibility state of any given column will be stored inside an XML file which is accessed via an Options class.

I'm trying to decide how best to represent those Boolean visibility values inside the Options class. I'm fairly sure I'll want properties exposing each column's visibility, but underneath those should there be a bool for each column or should I consider using a Dictionary or similar to hold all the column visibility values in one place?

The way I see it individual bools is probably a bit more robust and less likely to result in missing column values or some such, but a Dictionary would probably reduce the total amount of code.

+2  A: 

If it's the only property you need to store for the columns, you could use a single string where 1 means the column is visible and 0 hidden.

<Columns Visible="00001011110111010101" />

Gordon Bell
+2  A: 

I would say using a Dictionary is better in case you need to store additional attributes (such as width of each column) in the future.

Chetan Sastry
A: 

Conceptually you're taking the first step in what ultimately is a desire to persist object state, so think about the problem that way. Since you're already committed to using XML for your persistence format, it should be a short step from where you are to your answer.

le dorfier
A: 

The way I elected to do it was to create an Enum with an entry for each column combined with a Dictionary to hold the visibility state and a property exposing each column value.

This makes it easy to store and retrieve the column values from my XML file (just enumerate through the Enum storing/retrieving the desired value from the dictionary for each Enum) while also providing a bit more safety than just using a naked dictionary.

Lawrence Johnston