C# questionnaire for windows ...

  • Thread starter Thread starter Lakesider
  • Start date Start date
L

Lakesider

Dear NG,

I want to create a dynamic questionnaire/survey application
with .NET / C#. I want to ask questions and have several answer types:
Yes/No, 1-10, list of answers, eg. "Dog", "Bird" and "Chicken"

My very general question is: how would you design this? A user control
for every question-type? How could you get the questions on one form?

I really looking forward hearing your tips, tricks and ideas.

Thank you very much

Rudi
 
You would simply use the correct control per question. If you have a yes/no
question, place Yes No RadioButtons next to the question. If you have a
question with a list of acceptable responses, use a listbox. This is what
controls are for. You shouldn't need user controls at all.

-Scott
 
Hmm.

I would create a control per question type.

I would create an interface like this:

public IRespondable
{
string ResponseValue {get;} //maybe this could be an int or guid instead
of a string
string ResponseText {get;}
bool SomethingIsSelected{get;}
}

Each of your controls would implement this interface.

That way, you could deal with each control on a interface level, and have a
guaranteed
ResponseValue
ResponseText
SomethingIsSelected

The last property would be used to make sure the user picked something, so
you can validate if all questions need a response.
 
Ooops, forgot the word "interface".

public interface IRespondable
{
string ResponseValue {get;}
string ResponseText {get;}
bool SomethingIsSelected{get;}
}
 
Why in the world would you go to all that trouble when the standard set of
controls provide for a return value and there are vaildation controls in
both the Web and Windows environments?
 
I would encapsulate all the logic into the control.

I'd pass it some data, perhaps a List<ListItem> or Dictionary<int,string>.

Then my work is done of a certain "control type". I don't have to keep
copy/pasting datasource= and databind() calls.

I'd let the internal code of the put the values into the germane control.
Aka, populate a dropdownlist with the items in the Dictionary<int,string>.


Then (when I'm ready to collect the data)....I could loop over them. ~as the
interface~ to pull out their data. I don't have to deal with each type as a
concrete at that point.

...

Then when I needed a new control that I haven't thought of yet, all I have
to do is implement the interface, and I don't have to change my "collect the
values" logic.


I could also create a MyControlFactory, and pass in a key or something, and
then if the end user decided they wanted to go form a DropDownListBox to
Radio buttons, I could make the change with either a simple key update, or
config file update.

http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!126.entry

He sounds like he's building a mini framework to handle his different
"answer the question" needs.

The difference is maintainable and updateable code. Versus the ole "just
code 'er on up" mentality.
 
I think you are inventing a sledghammer where a simple solution is already
available.

The OP tells us he/she is looking for Yes/No, pick from list types of
questions and there are standard controls and databinding mechanisms for
these controls to solve this need without having to reinvent the wheel.

-Scott
 
Back
Top