private void cmdClearAnswer_Click(object sender, EventArgs e)
        {
            ClearInputBoxes();
            cmdClearAnswer.Visible = false;

            QuestionAnsweredEventArgs qe = new QuestionAnsweredEventArgs();

            qe.Choice = _choice;

            if (QuestionCleared != null)
            {
                QuestionCleared(this, qe);
            }

            try
            {
                _choice.Delete();
                _choice = null;
            }
            catch (Exception err)
            {
                LoggingHelper.Log("Error deleting choice in CallQuestionAnswerDisplay.ClearAnswer", LogSeverity.Error, err, false);
                MessageBox.Show(this, "An error occurred erasing your choice. Please report the following error to a system administrator:\n\n" +
                                err.Message, "Error removing choice");
            }
        }
        private void UpdateAnswer(string answer)
        {
            string answerText = answer;

            if (Choice != null)
            {
                if (Choice.LinkedCall.ReadOnly)
                {
                    return; // Cancel edit (this is a past call)
                }
            }
            else
            {
                _choice = GetNewCallChoice();
            }

            if (Question.type == question.QuestionTypes.YesNo)
            {
                if (answer == true.ToString())
                {
                    answerText = "Yes";
                    Text       = Question.text + ": Yes";
                }
                else if (answer == false.ToString())
                {
                    answerText = "No";
                    Text       = Question.text + ": No";
                }
            }
            else
            {
                Text = Question.text + ": " + Choice.answer;
            }
            _choice.answer = answerText;
            QuestionAnsweredEventArgs ea = new QuestionAnsweredEventArgs();

            ea.Choice = _choice;

            if (QuestionAnswered != null)
            {
                QuestionAnswered(this, ea);
            }


            Choice.Save();
            // currentChoiceIsDirty = true;

            cmdClearAnswer.Visible = true;
        }
        void cqad_QuestionCleared(object sender, QuestionAnsweredEventArgs e)
        {
            _questionsAnsweredCount--;
            if (QuestionCleared != null)
            {
                QuestionCleared(this, new QuestionAnsweredEventArgs());
            }

            if (_choices.Contains(e.Choice))
            {
                _choices.Remove(e.Choice);
            }

            CallQuestionAnswerDisplay sentBy = (CallQuestionAnswerDisplay)sender;

            if (sentBy.Question.is_fork)
            {
                HideQuestions(sentBy, "");
            }
        }
        void cqad_QuestionAnswered(object sender, QuestionAnsweredEventArgs e)
        {
            _questionsAnsweredCount++;
            CallQuestionAnswerDisplay sentBy = (CallQuestionAnswerDisplay)sender;

            if (sentBy.Question.is_fork)
            {
                pnlControls.SuspendLayout();
                pnlControls.AutoScroll = false;
                HideQuestions(sentBy, e.Choice.answer);

                // Need to show all subquestions here
                List <Control> toShow = GetChildQuestionsRecursive(sentBy.Question, e.Choice.answer);


                int totalAddedHeight = 0;
                // Controls aren't showing properly because controls in toShow aren't sorted by tabindex
                // Is likely also the problem with control hiding
                toShow.Sort(delegate(Control c1, Control c2) { return(c1.TabIndex.CompareTo(c2.TabIndex)); });

                int lastBottom = 0;
                if (toShow.Count > 0)
                {
                    lastBottom = GetTop(toShow[0].TabIndex);
                }
                foreach (Control aControl in toShow)
                {
                    int top = 0;
                    if (aControl is LabelWithCategory)
                    {
                        ((LabelWithCategory)aControl).IsHidden = false;
                        aControl.Height = ((LabelWithCategory)aControl).DefaultHeight;
                        top             = lastBottom + CATEGORYSPACER;
                    }
                    else if (aControl is CallQuestionAnswerDisplay)
                    {
                        ((CallQuestionAnswerDisplay)aControl).IsHidden = false;
                        aControl.Height = ((CallQuestionAnswerDisplay)aControl).DefaultHeight;
                        top             = lastBottom + SPACER;
                    }



                    totalAddedHeight += aControl.Height;
                    aControl.Location = new Point(aControl.Location.X, top);
                    lastBottom        = aControl.Bottom;
                }

                if (toShow.Count > 0)
                {
                    for (int i = toShow[toShow.Count - 1].TabIndex + 1; i < formControls[currentParentCategory.id].Count; i++)
                    {
                        formControls[currentParentCategory.id][i].Top += totalAddedHeight;
                    }
                }

                pnlControls.ResumeLayout();
                pnlControls.AutoScroll = true;
            }

            if (!_choices.Contains(e.Choice))
            {
                _choices.Add(e.Choice);
            }

            if (QuestionAnswered != null)
            {
                QuestionAnswered(sender, e);
            }
        }