Click here to Skip to main content
11,709,581 members (57,838 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 4: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 530
1 OriginalGriff 250
2 Peter Leow 229
3 Maciej Los 185
4 Mika Wendelius 160
0 OriginalGriff 9,428
1 Sergey Alexandrovich Kryukov 9,037
2 CPallini 5,189
3 Maciej Los 4,991
4 Mika Wendelius 3,856

Advertise | Privacy | Mobile
Web02 | 2.8.150819.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