Is there a way to avoid repetitive code in the following switch statement? I have the following method, which is called every time the user clicks a checkbox within a Datagrid. Each column within this Datagrid has a box in its header, which checks/unchecks all child checkboxes in the respective column. This header checkbox will be updated according to the child checkboxes by the method. 

My problem is that there is a lot of repetitive code in it since we do the same operation for each property (column) based on the checkbox that was clicked. 

Here is the code:

    /// &lt;summary&gt;
    /// Sets the Columnsheadercheckbox based on the individual checkbox values of the respective filter
    /// &lt;/summary&gt;
    private void SetHeaderCheckbox(string filterProperty = null)
    {
        if (GridData.Count == 0) return;
        var filter = GridData[0];
        DataGridDropdownProperty found;
        if (filterProperty == null) filterProperty = "all";
        switch (filterProperty)
        {
            case "SuperImpose":
                found = GridData.FirstOrDefault(f =&gt; f.SplitOver != filter.SplitOver);
                if (found == null)
                {
                    SuperimposeHeaderCheckbox = filter.SplitOver;
                }
                else
                {
                    SuperimposeHeaderCheckbox = null;
                }
                break;
            case "Normalize":
                found = GridData.FirstOrDefault(f =&gt; f.ToNormalize != filter.ToNormalize);
                if (found == null)
                {
                    NormalizeByHeaderCheckbox = filter.ToNormalize;
                }
                else
                {
                    NormalizeByHeaderCheckbox = null;
                }
                break;
            case "Legend":
                found = GridData.FirstOrDefault(f =&gt; f.ToLegend != filter.ToLegend);
                if (found == null)
                {
                    LegendHeaderCheckbox = filter.ToLegend;
                }
                else
                {
                    LegendHeaderCheckbox = null;
                }
                break;
            case "all":
                // Superimpose
                found = GridData.FirstOrDefault(f =&gt; f.SplitOver != filter.SplitOver);
                if (found == null)
                {
                    SuperimposeHeaderCheckbox = filter.SplitOver;
                }
                else
                {
                    SuperimposeHeaderCheckbox = null;
                }
                // Normalize
                found = GridData.FirstOrDefault(f =&gt; f.ToNormalize != filter.ToNormalize);
                if (found == null)
                {
                    NormalizeByHeaderCheckbox = filter.ToNormalize;
                }
                else
                {
                    NormalizeByHeaderCheckbox = null;
                }
                // Legend
                found = GridData.FirstOrDefault(f =&gt; f.ToLegend != filter.ToLegend);
                if (found == null)
                {
                    LegendHeaderCheckbox = filter.ToLegend;
                }
                else
                {
                    LegendHeaderCheckbox = null;
                }
                break;
        }
    }


My question is, if this kind of code is 'OK' or if it is, this is terrible practice, and there should be a more elegant way around it. (btw. Ignore the hardcoded strings. This is to illustrate the example)
Replace the if-else statements under each case with inline if statements. You can remove the if-else repetitions. For example..

SuperimposeHeaderCheckbox = found ? null : filter.SplitOver;

You can use turn filterProperty into an enumeration (instead of a string).

enum flags {SuperImpose=1, Normalize=2, Legend=4, all=7};

Finally, replace the switch-case statement with simple if statements. You can remove the repetitions for the case all.

if (filterProperty &amp; flags.SuperImpose) {
 // your code here
}
if (filterProperty &amp; flags.Normalize) {
 // your code here
}
if (filterProperty &amp; flags.Legend) {
 // your code here
}
// No need for a fourth if statement.

If you furthur want to reduce the number of the above if statements, you can map the properties in filter to the values in the enumeration and loop through the map.