Having an array of boolean values, is it possible to display it in excel as check boxes?

May 2, 2014 at 9:53 PM
Pretty self-explanatory, i get an array of boolean values from an SQL DB, and im able to display it in excel trough a simple method

public static object[] GetBools(int n)
    {
        bool[] boolArray= new bool[n];
        int i = 0;

        String ConnStr = @"Data So.......";

        SqlConnection conn = new SqlConnection(ConnStr);
        conn.Open();

        DataSet d = new DataSet();
        SqlCommand com = new SqlCommand(@"SELECT TOP "+ n.ToString() + " TrueOrFalse  FROM Person", conn);

        SqlDataAdapter sda = new SqlDataAdapter();
        sda.SelectCommand = com;
        sda.Fill(d);

        DataTable data = d.Tables[0];

        foreach (DataRow dr in data.Rows)
        {
            boolArray[i] = dr[0].ToString();
            i++;
        }
        return boolArray;
    }
Is there a way that instead of displaying true or false in the cells I could display a check box? (checked for true, unchecked for false)

Thank you very much,
Maximus.
Coordinator
May 3, 2014 at 1:31 AM
Hi,

If it's just for display, you might look for some way to do it with the icons in Conditional Formatting.
To actually add a CheckBox control you'd go into the Developer tab and Insert a CheckBox control, then link the value to the cell, though the alignment and stuff can be tricky.

To automate this in a macro you might first record the steps in VBA, then try to convert that into a macro that you run after the calculation is complete to fix up that column.

-Govert