Dynamic event handling

N

navin

Hi,
i have posted it before but i got no help...

I am developing a quiz application where the answers for the quiz vary
in number, so i am creating checkbox and radio buttons depending on the

database result.
now my problem is i have to check the which controls are checked in a
button click.
I dont know how many controls will be added to the form. So how do i
actually catch the events.

Help me in this context..


bye,
navin
 
T

Tasos Vogiatzoglou

This example should help you

private void CreateComponents(string[] questions) {
for (int i=0;i<questions.Length;i++){
CheckBox chkBox = new CheckBox();
chkBox.Name = "chk"+i;
chkBox.Text = questions;
chkBox.Click += new System.EventHandler(this.CheckBoxHandler);
}
}

private void CheckBoxHandler(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
//and here you have access at the checkbox
}

Tasos
 
N

navin

Hi,
thanks for your answer,but i am not able to catch the event from the
code. I am using vb.net can u give me event handler ie., how to write
that one in vb.net.

thanks
navin
 
T

Tasos Vogiatzoglou

Navin,

unfortunately I don't know VB.NET so I can not help you with that. The
sure is that the code above can handle events fror n dynamicly created
controls.

Try to adapt it to vb... or anyone else ?

Regards,
Tasos
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top