By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

Displaying a set of questions

P: n/a
Hi, I am using Visual C# window to dispaly a set of questions with their
answers. The users should be able to move to the next question by clicking on
next button. I am going to use only one panel to display one question and
move to next question. Can someone please help me with the codes on coding
"Next" button?
Thanks
--
Nejadian
Jun 27 '08 #1
Share this Question
Share on Google+
16 Replies


P: n/a

"Tammy Nejadian" <Ta***********@discussions.microsoft.comwrote in message
news:16**********************************@microsof t.com...
Hi, I am using Visual C# window to dispaly a set of questions with their
answers. The users should be able to move to the next question by clicking
on
next button. I am going to use only one panel to display one question and
move to next question. Can someone please help me with the codes on
coding
"Next" button?
Thanks
You need to hook up a datagrid with horizontal and vertical bars to move up
and down the questions or left or right on a question, with all the
questions being asked on one screen maybe two the at most.

From an end-user standpoint, there is nothing worst than going through 100
screens of individual questions (one question per screen) because the
programmer couldn't come up with something else that was better.

All the end-user is going to say is "who wrote this thing".

Jun 27 '08 #2

P: n/a
<snip>

Mr. Arnold: regarding your comments:
From an end-user standpoint, there is nothing worst than going through 100
screens of individual questions (one question per screen) because the
programmer couldn't come up with something else that was better.
This is just plain bad advice and/or guidance. There are many good reasons
to present one question at a time. Online examinations typically present one
question at a time, with the ability at the end to jump directly back to any
question to review the answer before completing the exam. Over the years I
have passed 19 Microsoft certification exams, and every one of them presents
one question at a time, with 'next' and 'back' buttons, like what the OP
apparently wants to provide.

-RC

Jun 27 '08 #3

P: n/a

"Robert Cramer" <A@B.comwrote in message
news:up**************@TK2MSFTNGP05.phx.gbl...
<snip>

Mr. Arnold: regarding your comments:
>From an end-user standpoint, there is nothing worst than going through
100 screens of individual questions (one question per screen) because
the programmer couldn't come up with something else that was better.

This is just plain bad advice and/or guidance. There are many good reasons
to present one question at a time. Online examinations typically present
one question at a time, with the ability at the end to jump directly back
to any question to review the answer before completing the exam. Over the
years I have passed 19 Microsoft certification exams, and every one of
them presents one question at a time, with 'next' and 'back' buttons, like
what the OP apparently wants to provide.

You don't know what the case or the scope of the questions will be for a
given solution.

I have worked on insurance applications that asked the insurance agent or
broker over 900 questions in various categories, with all of it being
displayed on one ASP.net page by selecting the various categories from combo
boxes with any where from 1 to 50 questions at a time with the answers to
questions given in combo, textbox and radio controls in a table or grid, and
all of it being built on the fly.

I have also done the same thing with questionnaire surveys for car companies
and their dealerships with their customers when asking about features in
cars based on make and model.

You can pass 10,000 MS certification tests with screen by screen questions.
That doesn't make it a standard that should be followed.

There was this one programmer who did just that. He developed a solution for
some in-house users that went screen by screen or page by page asking
questions, they wouldn't use his application, and they talked about him
like a dog.

You don't know the scope of the of this, what I have suggest my be the best
approach, and the OP doesn't know that or doesn't know any better, not to go
screen by screen.

One programs the screen by screen solution may be a viable solution, but on
the other hand, it may not be a viable solution too.
Jun 27 '08 #4

P: n/a
Responses inline:

>Mr. Arnold: regarding your comments:
>>From an end-user standpoint, there is nothing worst than going through
100 screens of individual questions (one question per screen) because
the programmer couldn't come up with something else that was better.

This is just plain bad advice and/or guidance. There are many good
reasons to present one question at a time. Online examinations typically
present one question at a time, with the ability at the end to jump
directly back to any question to review the answer before completing the
exam. Over the years I have passed 19 Microsoft certification exams, and
every one of them presents one question at a time, with 'next' and 'back'
buttons, like what the OP apparently wants to provide.


You don't know what the case or the scope of the questions will be for a
given solution.

I have worked on insurance applications that asked the insurance agent or
broker over 900 questions in various categories, with all of it being
displayed on one ASP.net page by selecting the various categories from
combo boxes with any where from 1 to 50 questions at a time with the
answers to questions given in combo, textbox and radio controls in a table
or grid, and all of it being built on the fly.
It sounds like you provided an excellent solution for their specific
problem. You are to be commended.

I have also done the same thing with questionnaire surveys for car
companies and their dealerships with their customers when asking about
features in cars based on make and model.
You apparently did a good thing, yet again.

You can pass 10,000 MS certification tests with screen by screen
questions. That doesn't make it a standard that should be followed.
I never stated or implied that what I was recommending was a standard. The
point I was making was that for some tests, it is perfectly reasonable to
present one question at a time. By bringing up the MS certification exams, I
was simply illustrating a real-world example of where this might be the best
approach. By stating the number of exams, I was pointing out that my
observations and experience are not entirely unique to one special case.

There was this one programmer who did just that. He developed a solution
for some in-house users that went screen by screen or page by page asking
questions, they wouldn't use his application, and they talked about him
like a dog.
So apparently he did the wrong thing. But that doesn't mean that presenting
one question at a time is always the wrong thing. Apparently you are
unfamiliar with progressive tests whereby expertise in some subject matter
is being measured via some "progressively determined" or dynamic set of
questions... whereby answers to early questions determine which questions
are presented next. Where expertise is confirmed early in a test, future
questions on that subject domain are omitted. Where expertise is not clearly
demonstrated, additional questions within the subject domain are dynamically
added to the exam... all this in an effort to get a more accurate
understanding of the expertise being measured. There is a lot of theory that
goes into these types of tests. You can google "psychometrics" for more.

Furthermore, what about plain ole' wizards. Sometimes they will present a
single question that determines what successive wizard pages are presented.

You don't know the scope of the of this, what I have suggest my be the
best approach, and the OP doesn't know that or doesn't know any better,
not to go screen by screen.
You don't know enough about the OP's motivations either, and jumped to a
conclusion that the OP doesn't know any better. I was simply pointing out
that you are wrong about that, provided some real-world examples (at least
19 that I have firsthand knowledge of).

My intention is to not be confrontational - but where somebody (the OP in
this case) is given bad advice, I'll point that out.... as doing so helps to
maintain the value of these NGs.

One programs the screen by screen solution may be a viable solution, but
on the other hand, it may not be a viable solution too.
Great! Apparently we agree. It's too bad that you didn't consider that with
your response to the OP and instead had to imply that the OP was doing
something wrong and proceeded to give very explicit advice to do something
based on your assumptions. To quote you: "You need to hook up a datagrid
with horizontal and vertical bars to move up and down the questions or left
or right on a question...". There is nothing there, or elsewhere in your
post, that helps the OP to solve their original problem.
-RC

Jun 27 '08 #5

P: n/a

"Robert Cramer" <A@B.comwrote in message
news:u5**************@TK2MSFTNGP03.phx.gbl...
Responses inline:

Great! Apparently we agree. It's too bad that you didn't consider that
with your response to the OP and instead had to imply that the OP was
doing something wrong and proceeded to give very explicit advice to do
something based on your assumptions. To quote you: "You need to hook up a
datagrid with horizontal and vertical bars to move up and down the
questions or left or right on a question...". There is nothing there, or
elsewhere in your post, that helps the OP to solve their original problem.

My goodness, It was a suggestion, and you made it much ado about nothing.
You would have been better off just posting to the OP, IMO.
Jun 27 '08 #6

P: n/a
One of your previous questions indicated you have a class containing the
question and the potential answers. Presuming this is still the case, I
recommend you create a user control which has a property for your Question
class.

The user control then handles the display of the question and answers. Your
form will have this control on it, as well as the Questions list of Question
objects. You then just incriment a counter in the list to go with the [Next]
button. Trap the condition where you are at the end of the list.

You can also add a [Previous] button which decriments the counter. In each
of these buttons you would simply update the Question object for the user
control and it would then display the new question.

"Tammy Nejadian" wrote:
Hi, I am using Visual C# window to dispaly a set of questions with their
answers. The users should be able to move to the next question by clicking on
next button. I am going to use only one panel to display one question and
move to next question. Can someone please help me with the codes on coding
"Next" button?
Thanks
--
Nejadian
Jun 27 '08 #7

P: n/a
On Apr 20, 10:53 pm, Tammy Nejadian
<TammyNejad...@discussions.microsoft.comwrote:
Hi, I am using Visual C# window to dispaly a set of questions with their
answers. The users should be able to move to the next question by clicking on
next button. I am going to use only one panel to display one question and
move to next question. Can someone please help me with the codes on coding
"Next" button?
Thanks
--
Nejadian
you don't provide enough information to determine what you really
want;
Is the set of questions displayed, or is a single question displayed
ata a time?
You say one question on one panel - but do you mean you want to
display many panels on the window simultaneously or a single panel on
the window, whose contents change (to the next question) when the next
button is preessed (like a wizard).

You also don't say how your questions (and answers) are stored. Are
they a collection of objects, a dataset, or something else?

Whatever the answers to the above, the essential code when clicking
the next button would be;

if (!WereLookingAtTheLastQuestion())
{
LookAtTheNextQuestion();
}

What you now need to figure out, is what will be in the two methods
WereLookingAtTheLastQuestion() and LookAtTheNextQuestion()

Assuming the questions are in an array, this could be as simple as
checking the current index against the array bounds, and incrementing
the current index and calling your 'display a question' method.

Good luck - and don't listen to those that tell you you're doing the
wrong thing when they don't know what you are doing!

..\\axxx
Jun 27 '08 #8

P: n/a
Thanks for your sugestions and advice. I am really appricated. I should be
more specific and explain my problem more clear. Actuly I suppose to read
from xml file and display the elements as questions and their answers. I am
able to create a panel and display the question in created label and display
the answers using radio buttons so the users can intract with them. I should
use one panel and display each question at the time and each time the user
click on button it will collect the information and display (or move to) the
next question. There should be another button which allows the user to go
back to last question if he/she wants to do that. However for now I am stock
in moving to next quesion. Could you please help me on that.
--
Nejadian
".\\\\axxx" wrote:
On Apr 20, 10:53 pm, Tammy Nejadian
<TammyNejad...@discussions.microsoft.comwrote:
Hi, I am using Visual C# window to dispaly a set of questions with their
answers. The users should be able to move to the next question by clicking on
next button. I am going to use only one panel to display one question and
move to next question. Can someone please help me with the codes on coding
"Next" button?
Thanks
--
Nejadian

you don't provide enough information to determine what you really
want;
Is the set of questions displayed, or is a single question displayed
ata a time?
You say one question on one panel - but do you mean you want to
display many panels on the window simultaneously or a single panel on
the window, whose contents change (to the next question) when the next
button is preessed (like a wizard).

You also don't say how your questions (and answers) are stored. Are
they a collection of objects, a dataset, or something else?

Whatever the answers to the above, the essential code when clicking
the next button would be;

if (!WereLookingAtTheLastQuestion())
{
LookAtTheNextQuestion();
}

What you now need to figure out, is what will be in the two methods
WereLookingAtTheLastQuestion() and LookAtTheNextQuestion()

Assuming the questions are in an array, this could be as simple as
checking the current index against the array bounds, and incrementing
the current index and calling your 'display a question' method.

Good luck - and don't listen to those that tell you you're doing the
wrong thing when they don't know what you are doing!

..\\axxx
Jun 27 '08 #9

P: n/a

"Tammy Nejadian" <Ta***********@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
Thanks for your sugestions and advice. I am really appricated. I should be
more specific and explain my problem more clear. Actuly I suppose to read
from xml file and display the elements as questions and their answers. I
am
able to create a panel and display the question in created label and
display
the answers using radio buttons so the users can intract with them. I
should
use one panel and display each question at the time and each time the user
click on button it will collect the information and display (or move to)
the
next question. There should be another button which allows the user to go
back to last question if he/she wants to do that. However for now I am
stock
in moving to next quesion. Could you please help me on that.
You read the XML with the tags of questions, you make an QuestionAnswer
object containing a property for the Question and a property for the Answer,
you load each QuestionAnswer with the Question from the XML, and you load
the QuestionAnswer object in to a List of QuestionAnswer objects. or you can
use an ArrayList too.

With the reading of each XML Question Element, you create the Object and
you load the question from the XML. It could be something like this.

private void LoadIntitialQuestions()
{

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
Read XML Question with a read loop;

QuestionAnswer qa = new QuestionAnswer();
qa.Question = XML.Question;
qa.Answer = null; // or whatever it takes to set it to not used.

questionsanswers .Add(qa);

}

Now you have all the initial QuestionAnswer objects in a List where you can
use an index to apply the Next or Back button as you move up and down the
List by index with 0 being the first element in the list and
questionsanswers.Count being the last possible element in the List.

Idx = 0;

Label1.Text = questionsanswers [idx].question;
textbox1.Text = questionsanswers[idx].answer;

Next button will increment idx = idx++ // by 1 until it hits the max count

You do the Back button the same way but idx = idx-- decrement by 1 until it
hits 0.

If you want to save the answer to a question to the object, it would be like
this.

questionsanswers[idx].answer = textbox1.text;

It's all based off of the QuestionAnswer object being loaded into a List or
ArrayList of QuestionsAnswers, and then you can move up and down the List of
objects and address them using an Index into the List of objects.



Jun 27 '08 #10

P: n/a
Thanks for the information. It seems that is what I am looking for, however
one of the codes gives me error message. I add a copy of my xml file and the
class I have that may give you better picture. I am really appreciating your
help.

class QuestionAnswer
{

private string qtext;
private string AnswerText;

public string Question1
{
get { return qtext; }
set { qtext = value; }
}

public string Question2
{
get { return AnswerText; }
set { AnswerText = value; }
}

public void loadTest()
{
XmlTextReader docTest = new XmlTextReader("QuestionAnswer.xml");

string stringElement1;
while (docTest.NodeType == XmlNodeType.Element)
{
for (int tabInteger = 0; tabInteger < docTest.Depth;
tabInteger++)

stringElement1 = docTest.Name;
if (docTest.NodeType == XmlNodeType.Text)
{
string stringElement2 = docTest.Value;
}
}

}

//The xml file:
<?xml version="1.0"?>
<tests>
<test>
<testid>3</testid>
<testass>Assessment</testass>
<questions>
<question>
<Question1ID>102</Question1ID>
<testid>3</testid>
<tqorderid>10</tqorderid>
<qtext>How Old are you?</qtext>
<Answers>
<Answer>
<Answer1ID>1</Answer1ID>
<AnswerText>Below 18</AnswerText>
</Answer>
<Answer>
<Answer1ID>2</Answer1ID>
<AnswerText>Above 18</AnswerText>
</Answer>
</Answers>
</question>
<question>
<Question1ID>202</Question1ID>
<testid>3</testid>
<tqorderid>20</tqorderid>
<qtext>How many sisters and brothers you have?</qtext>
<Answers>
<Answer>
<Answer1ID>1</Answer1ID>
<AnswerText>One</AnswerText>
</Answer>
<Answer>
<Answer1ID>2</Answer1ID>
<AnswerText>Two</AnswerText>
</Answer>
<Answer>
<Answer1ID>3</Answer1ID>
<AnswerText>Three</AnswerText>
</Answer>
<Answer>
<Answer1ID>4</Answer1ID>
<AnswerText>Four</AnswerText>
</Answer>
</Answers>
</question>
<test>
<testid>4</testid>
<testass>Assessment2</testass>
</test>
</questions>
</test>
</tests>
--
Nejadian
"Mr. Arnold" wrote:
>
"Tammy Nejadian" <Ta***********@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
Thanks for your sugestions and advice. I am really appricated. I should be
more specific and explain my problem more clear. Actuly I suppose to read
from xml file and display the elements as questions and their answers. I
am
able to create a panel and display the question in created label and
display
the answers using radio buttons so the users can intract with them. I
should
use one panel and display each question at the time and each time the user
click on button it will collect the information and display (or move to)
the
next question. There should be another button which allows the user to go
back to last question if he/she wants to do that. However for now I am
stock
in moving to next quesion. Could you please help me on that.

You read the XML with the tags of questions, you make an QuestionAnswer
object containing a property for the Question and a property for the Answer,
you load each QuestionAnswer with the Question from the XML, and you load
the QuestionAnswer object in to a List of QuestionAnswer objects. or you can
use an ArrayList too.

With the reading of each XML Question Element, you create the Object and
you load the question from the XML. It could be something like this.

private void LoadIntitialQuestions()
{

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
Read XML Question with a read loop;

QuestionAnswer qa = new QuestionAnswer();
qa.Question = XML.Question;
qa.Answer = null; // or whatever it takes to set it to not used.

questionsanswers .Add(qa);

}

Now you have all the initial QuestionAnswer objects in a List where you can
use an index to apply the Next or Back button as you move up and down the
List by index with 0 being the first element in the list and
questionsanswers.Count being the last possible element in the List.

Idx = 0;

Label1.Text = questionsanswers [idx].question;
textbox1.Text = questionsanswers[idx].answer;

Next button will increment idx = idx++ // by 1 until it hits the max count

You do the Back button the same way but idx = idx-- decrement by 1 until it
hits 0.

If you want to save the answer to a question to the object, it would be like
this.

questionsanswers[idx].answer = textbox1.text;

It's all based off of the QuestionAnswer object being loaded into a List or
ArrayList of QuestionsAnswers, and then you can move up and down the List of
objects and address them using an Index into the List of objects.



Jun 27 '08 #11

P: n/a

"Tammy Nejadian" <Ta***********@discussions.microsoft.comwrote in message
news:C9**********************************@microsof t.com...
Thanks for the information. It seems that is what I am looking for,
however
one of the codes gives me error message. I add a copy of my xml file and
the
class I have that may give you better picture. I am really appreciating
your
help.
What error message would that be and at what point does the application
blow-up?

Jun 27 '08 #12

P: n/a
I used your code you posted. I named my class QuestionAnswer same as my xml
file name however I get error message on this line:

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();

it says
--
Nejadian
"Tammy Nejadian" wrote:
Thanks for the information. It seems that is what I am looking for, however
one of the codes gives me error message. I add a copy of my xml file and the
class I have that may give you better picture. I am really appreciating your
help.

class QuestionAnswer
{

private string qtext;
private string AnswerText;

public string Question1
{
get { return qtext; }
set { qtext = value; }
}

public string Question2
{
get { return AnswerText; }
set { AnswerText = value; }
}

public void loadTest()
{
XmlTextReader docTest = new XmlTextReader("QuestionAnswer.xml");

string stringElement1;
while (docTest.NodeType == XmlNodeType.Element)
{
for (int tabInteger = 0; tabInteger < docTest.Depth;
tabInteger++)

stringElement1 = docTest.Name;
if (docTest.NodeType == XmlNodeType.Text)
{
string stringElement2 = docTest.Value;
}
}

}

//The xml file:
<?xml version="1.0"?>
<tests>
<test>
<testid>3</testid>
<testass>Assessment</testass>
<questions>
<question>
<Question1ID>102</Question1ID>
<testid>3</testid>
<tqorderid>10</tqorderid>
<qtext>How Old are you?</qtext>
<Answers>
<Answer>
<Answer1ID>1</Answer1ID>
<AnswerText>Below 18</AnswerText>
</Answer>
<Answer>
<Answer1ID>2</Answer1ID>
<AnswerText>Above 18</AnswerText>
</Answer>
</Answers>
</question>
<question>
<Question1ID>202</Question1ID>
<testid>3</testid>
<tqorderid>20</tqorderid>
<qtext>How many sisters and brothers you have?</qtext>
<Answers>
<Answer>
<Answer1ID>1</Answer1ID>
<AnswerText>One</AnswerText>
</Answer>
<Answer>
<Answer1ID>2</Answer1ID>
<AnswerText>Two</AnswerText>
</Answer>
<Answer>
<Answer1ID>3</Answer1ID>
<AnswerText>Three</AnswerText>
</Answer>
<Answer>
<Answer1ID>4</Answer1ID>
<AnswerText>Four</AnswerText>
</Answer>
</Answers>
</question>
<test>
<testid>4</testid>
<testass>Assessment2</testass>
</test>
</questions>
</test>
</tests>
--
Nejadian
"Mr. Arnold" wrote:

"Tammy Nejadian" <Ta***********@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
Thanks for your sugestions and advice. I am really appricated. I should be
more specific and explain my problem more clear. Actuly I suppose to read
from xml file and display the elements as questions and their answers. I
am
able to create a panel and display the question in created label and
display
the answers using radio buttons so the users can intract with them. I
should
use one panel and display each question at the time and each time the user
click on button it will collect the information and display (or move to)
the
next question. There should be another button which allows the user to go
back to last question if he/she wants to do that. However for now I am
stock
in moving to next quesion. Could you please help me on that.
You read the XML with the tags of questions, you make an QuestionAnswer
object containing a property for the Question and a property for the Answer,
you load each QuestionAnswer with the Question from the XML, and you load
the QuestionAnswer object in to a List of QuestionAnswer objects. or you can
use an ArrayList too.

With the reading of each XML Question Element, you create the Object and
you load the question from the XML. It could be something like this.

private void LoadIntitialQuestions()
{

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
Read XML Question with a read loop;

QuestionAnswer qa = new QuestionAnswer();
qa.Question = XML.Question;
qa.Answer = null; // or whatever it takes to set it to not used.

questionsanswers .Add(qa);

}

Now you have all the initial QuestionAnswer objects in a List where you can
use an index to apply the Next or Back button as you move up and down the
List by index with 0 being the first element in the list and
questionsanswers.Count being the last possible element in the List.

Idx = 0;

Label1.Text = questionsanswers [idx].question;
textbox1.Text = questionsanswers[idx].answer;

Next button will increment idx = idx++ // by 1 until it hits the max count

You do the Back button the same way but idx = idx-- decrement by 1 until it
hits 0.

If you want to save the answer to a question to the object, it would be like
this.

questionsanswers[idx].answer = textbox1.text;

It's all based off of the QuestionAnswer object being loaded into a List or
ArrayList of QuestionsAnswers, and then you can move up and down the List of
objects and address them using an Index into the List of objects.




Jun 27 '08 #13

P: n/a
Tammy,

I used your class, creating an instance of it, and called the loadTest
method. The while loop is never entered, and so Question1 and Question2 both
return "".

Regarding your message about using Mr. Arnold's code, you said:

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
That should fail. The line (I believe) should be:

List<QuestionAnswerquestionanswers = new List<QuestionAnswer>();
"Tammy Nejadian" wrote:
Thanks for the information. It seems that is what I am looking for, however
one of the codes gives me error message. I add a copy of my xml file and the
class I have that may give you better picture. I am really appreciating your
help.

class QuestionAnswer
{

private string qtext;
private string AnswerText;

public string Question1
{
get { return qtext; }
set { qtext = value; }
}

public string Question2
{
get { return AnswerText; }
set { AnswerText = value; }
}

public void loadTest()
{
XmlTextReader docTest = new XmlTextReader("QuestionAnswer.xml");

string stringElement1;
while (docTest.NodeType == XmlNodeType.Element)
{
for (int tabInteger = 0; tabInteger < docTest.Depth;
tabInteger++)

stringElement1 = docTest.Name;
if (docTest.NodeType == XmlNodeType.Text)
{
string stringElement2 = docTest.Value;
}
}

}

//The xml file:
<?xml version="1.0"?>
<tests>
<test>
<testid>3</testid>
<testass>Assessment</testass>
<questions>
<question>
<Question1ID>102</Question1ID>
<testid>3</testid>
<tqorderid>10</tqorderid>
<qtext>How Old are you?</qtext>
<Answers>
<Answer>
<Answer1ID>1</Answer1ID>
<AnswerText>Below 18</AnswerText>
</Answer>
<Answer>
<Answer1ID>2</Answer1ID>
<AnswerText>Above 18</AnswerText>
</Answer>
</Answers>
</question>
<question>
<Question1ID>202</Question1ID>
<testid>3</testid>
<tqorderid>20</tqorderid>
<qtext>How many sisters and brothers you have?</qtext>
<Answers>
<Answer>
<Answer1ID>1</Answer1ID>
<AnswerText>One</AnswerText>
</Answer>
<Answer>
<Answer1ID>2</Answer1ID>
<AnswerText>Two</AnswerText>
</Answer>
<Answer>
<Answer1ID>3</Answer1ID>
<AnswerText>Three</AnswerText>
</Answer>
<Answer>
<Answer1ID>4</Answer1ID>
<AnswerText>Four</AnswerText>
</Answer>
</Answers>
</question>
<test>
<testid>4</testid>
<testass>Assessment2</testass>
</test>
</questions>
</test>
</tests>
--
Nejadian
"Mr. Arnold" wrote:

"Tammy Nejadian" <Ta***********@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
Thanks for your sugestions and advice. I am really appricated. I should be
more specific and explain my problem more clear. Actuly I suppose to read
from xml file and display the elements as questions and their answers. I
am
able to create a panel and display the question in created label and
display
the answers using radio buttons so the users can intract with them. I
should
use one panel and display each question at the time and each time the user
click on button it will collect the information and display (or move to)
the
next question. There should be another button which allows the user to go
back to last question if he/she wants to do that. However for now I am
stock
in moving to next quesion. Could you please help me on that.
You read the XML with the tags of questions, you make an QuestionAnswer
object containing a property for the Question and a property for the Answer,
you load each QuestionAnswer with the Question from the XML, and you load
the QuestionAnswer object in to a List of QuestionAnswer objects. or you can
use an ArrayList too.

With the reading of each XML Question Element, you create the Object and
you load the question from the XML. It could be something like this.

private void LoadIntitialQuestions()
{

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
Read XML Question with a read loop;

QuestionAnswer qa = new QuestionAnswer();
qa.Question = XML.Question;
qa.Answer = null; // or whatever it takes to set it to not used.

questionsanswers .Add(qa);

}

Now you have all the initial QuestionAnswer objects in a List where you can
use an index to apply the Next or Back button as you move up and down the
List by index with 0 being the first element in the list and
questionsanswers.Count being the last possible element in the List.

Idx = 0;

Label1.Text = questionsanswers [idx].question;
textbox1.Text = questionsanswers[idx].answer;

Next button will increment idx = idx++ // by 1 until it hits the max count

You do the Back button the same way but idx = idx-- decrement by 1 until it
hits 0.

If you want to save the answer to a question to the object, it would be like
this.

questionsanswers[idx].answer = textbox1.text;

It's all based off of the QuestionAnswer object being loaded into a List or
ArrayList of QuestionsAnswers, and then you can move up and down the List of
objects and address them using an Index into the List of objects.




Jun 27 '08 #14

P: n/a
Thanks, it solved the problem. Many thanks to all of you, I am really
appreciated your help.
--
Nejadian
"Family Tree Mike" wrote:
Tammy,

I used your class, creating an instance of it, and called the loadTest
method. The while loop is never entered, and so Question1 and Question2 both
return "".

Regarding your message about using Mr. Arnold's code, you said:

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
That should fail. The line (I believe) should be:

List<QuestionAnswerquestionanswers = new List<QuestionAnswer>();
"Tammy Nejadian" wrote:
Thanks for the information. It seems that is what I am looking for, however
one of the codes gives me error message. I add a copy of my xml file and the
class I have that may give you better picture. I am really appreciating your
help.

class QuestionAnswer
{

private string qtext;
private string AnswerText;

public string Question1
{
get { return qtext; }
set { qtext = value; }
}

public string Question2
{
get { return AnswerText; }
set { AnswerText = value; }
}

public void loadTest()
{
XmlTextReader docTest = new XmlTextReader("QuestionAnswer.xml");

string stringElement1;
while (docTest.NodeType == XmlNodeType.Element)
{
for (int tabInteger = 0; tabInteger < docTest.Depth;
tabInteger++)

stringElement1 = docTest.Name;
if (docTest.NodeType == XmlNodeType.Text)
{
string stringElement2 = docTest.Value;
}
}

}

//The xml file:
<?xml version="1.0"?>
<tests>
<test>
<testid>3</testid>
<testass>Assessment</testass>
<questions>
<question>
<Question1ID>102</Question1ID>
<testid>3</testid>
<tqorderid>10</tqorderid>
<qtext>How Old are you?</qtext>
<Answers>
<Answer>
<Answer1ID>1</Answer1ID>
<AnswerText>Below 18</AnswerText>
</Answer>
<Answer>
<Answer1ID>2</Answer1ID>
<AnswerText>Above 18</AnswerText>
</Answer>
</Answers>
</question>
<question>
<Question1ID>202</Question1ID>
<testid>3</testid>
<tqorderid>20</tqorderid>
<qtext>How many sisters and brothers you have?</qtext>
<Answers>
<Answer>
<Answer1ID>1</Answer1ID>
<AnswerText>One</AnswerText>
</Answer>
<Answer>
<Answer1ID>2</Answer1ID>
<AnswerText>Two</AnswerText>
</Answer>
<Answer>
<Answer1ID>3</Answer1ID>
<AnswerText>Three</AnswerText>
</Answer>
<Answer>
<Answer1ID>4</Answer1ID>
<AnswerText>Four</AnswerText>
</Answer>
</Answers>
</question>
<test>
<testid>4</testid>
<testass>Assessment2</testass>
</test>
</questions>
</test>
</tests>
--
Nejadian
"Mr. Arnold" wrote:
>
"Tammy Nejadian" <Ta***********@discussions.microsoft.comwrote in message
news:90**********************************@microsof t.com...
Thanks for your sugestions and advice. I am really appricated. I should be
more specific and explain my problem more clear. Actuly I suppose to read
from xml file and display the elements as questions and their answers. I
am
able to create a panel and display the question in created label and
display
the answers using radio buttons so the users can intract with them. I
should
use one panel and display each question at the time and each time the user
click on button it will collect the information and display (or move to)
the
next question. There should be another button which allows the user to go
back to last question if he/she wants to do that. However for now I am
stock
in moving to next quesion. Could you please help me on that.
>
You read the XML with the tags of questions, you make an QuestionAnswer
object containing a property for the Question and a property for the Answer,
you load each QuestionAnswer with the Question from the XML, and you load
the QuestionAnswer object in to a List of QuestionAnswer objects. or you can
use an ArrayList too.
>
With the reading of each XML Question Element, you create the Object and
you load the question from the XML. It could be something like this.
>
private void LoadIntitialQuestions()
{
>
List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
>
>
Read XML Question with a read loop;
>
QuestionAnswer qa = new QuestionAnswer();
qa.Question = XML.Question;
qa.Answer = null; // or whatever it takes to set it to not used.
>
questionsanswers .Add(qa);
>
}
>
Now you have all the initial QuestionAnswer objects in a List where you can
use an index to apply the Next or Back button as you move up and down the
List by index with 0 being the first element in the list and
questionsanswers.Count being the last possible element in the List.
>
Idx = 0;
>
Label1.Text = questionsanswers [idx].question;
textbox1.Text = questionsanswers[idx].answer;
>
Next button will increment idx = idx++ // by 1 until it hits the max count
>
You do the Back button the same way but idx = idx-- decrement by 1 until it
hits 0.
>
If you want to save the answer to a question to the object, it would be like
this.
>
questionsanswers[idx].answer = textbox1.text;
>
It's all based off of the QuestionAnswer object being loaded into a List or
ArrayList of QuestionsAnswers, and then you can move up and down the List of
objects and address them using an Index into the List of objects.
>
>
>
>
>
>
>
>
>
>
>
>
Jun 27 '08 #15

P: n/a

"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:46**********************************@microsof t.com...
Tammy,

I used your class, creating an instance of it, and called the loadTest
method. The while loop is never entered, and so Question1 and Question2
both
return "".

Regarding your message about using Mr. Arnold's code, you said:

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
That should fail. The line (I believe) should be:

List<QuestionAnswerquestionanswers = new List<QuestionAnswer>();

I don't know. The least he could have done was look up the List statement.
He was lucky he got anything out of me at 3:00 am when I woke up to take a
pi$$ and went back to sleep. <g>

There is also the auto completion-key. What is it shift-key space bar-key?
The use of the key combination would have just about completed the statement
for him after the *new* key word.
Jun 27 '08 #16

P: n/a
I hope I get respond to this question. I posted long time ago. Anyway how I
can call and display the question and its answers when I click a button?
Thanks.
--
Nejadian
"Mr. Arnold" wrote:
>
"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:46**********************************@microsof t.com...
Tammy,

I used your class, creating an instance of it, and called the loadTest
method. The while loop is never entered, and so Question1 and Question2
both
return "".

Regarding your message about using Mr. Arnold's code, you said:

List<QuestionAnswerquestionsanswers = new <QuestionAnswer>();
That should fail. The line (I believe) should be:

List<QuestionAnswerquestionanswers = new List<QuestionAnswer>();

I don't know. The least he could have done was look up the List statement.
He was lucky he got anything out of me at 3:00 am when I woke up to take a
pi$$ and went back to sleep. <g>

There is also the auto completion-key. What is it shift-key space bar-key?
The use of the key combination would have just about completed the statement
for him after the *new* key word.
Jun 27 '08 #17

This discussion thread is closed

Replies have been disabled for this discussion.