Click here to Skip to main content
11,480,626 members (64,953 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
I am doing a small project in c#. It is like a questionaire. Administrator has the option to add as many questions she want and the answer type may also differ for each question.The questions are coming from database . I am storing all the questions in a datagridview. How can I create the questions and its answer type dynamically based on the number of questions in a datagridview
Posted 13-Nov-12 5:29am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

By changing the data source to contain the questions and answers you want it to, and then writing code that can bind to that data source. There's no controls to add dynamically here, you're showing data in a databound control, so you just need to change the data. I'd expect this would be a data bound control for each question, with a databound control inside it for an arbitrary number of answers. Hard to say more, as you give no clues what you're using ( WPF, winforms, silverlight, ASP.NET, MVC, etc )
lilian87 at 13-Nov-12 10:34am
It is a desktop application in c#
Christian Graus at 13-Nov-12 10:37am
Still not enough. Winforms ? WPF ?
lilian87 at 13-Nov-12 10:38am
Christian Graus at 13-Nov-12 10:54am
So to add a control, you just create it, set it's position ( top, width etc ) and add it to the form's 'controls' collection, as in this.Controls.Add(x);. But again, you should not need to do that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 294
1 OriginalGriff 190
2 CPallini 150
3 Richard MacCutchan 150
4 CHill60 130
0 Sergey Alexandrovich Kryukov 8,184
1 OriginalGriff 7,556
2 Sascha Lefèvre 3,114
3 Maciej Los 2,491
4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web03 | 2.8.150520.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100