0

I am trying to create a switch statement which adds a 1,2 or 3 to the question type column of my questionDataTable depending on which checkbox is ticked in the corresponding row to the Question ID row which I am trying to increment every time the button is pressed. I'm not sure if I should create the row and then increment the ID or would that create an error because ID is not allowed to be NULL.

I have looked around and can't seem to find any resources to help me.

private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        this.checkBox2.Enabled = !this.checkBox1.Checked;
        this.checkBox3.Enabled = !this.checkBox1.Checked;
        if (!this.checkBox2.Enabled)
        {
            this.checkBox2.Checked = false;
            this.checkBox3.Checked = false;
        }

    }

    private void checkBox2_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void checkBox3_CheckedChanged(object sender, EventArgs e)
    {

    }

    private void button1_Click(object sender, EventArgs e)
    {
        if(checkBox1.Checked)
        {

            this.questionDataTableBindingSource.AddNew();

            int questiontype = 0;
            switch (questiontype)
            { 
                case1:
                    this.Validate();



            }
mot375
  • 99
  • 1
  • 13
  • 2
    You might want to consider radio buttons as opposed to check boxes. – Dan Bracuk Apr 15 '15 at 11:45
  • Are you possibly referring to automatically incrementing the primary key - http://stackoverflow.com/questions/10991894/auto-increment-primary-key-in-sql-server-management-studio-2012 ? – Kami Apr 15 '15 at 11:46

1 Answers1

0

You could add a record and leave it null, so long as that column accepts nulls. But in my opinion I would add it all together, makes things tidier and one less query for your database (server). Something like this;

int questiontype = bool.Equals(checkBox1.Checked, true) ? 1 :
    bool.Equals(checkBox2.Checked, true) ? 2 : 3;

But this brings with it problems as you can tick two checkboxes at once. You could add in your Checked_Changed handlers the functionality to uncheck other boxes as you select one. However, as Dan Bracuk suggests (+1) - Radio Buttons will be your friends here!

horHAY
  • 788
  • 2
  • 10
  • 23