help guys... c# windows form

M

mohit_raghav2003

I have have to check if the dynamically created radiobutton is checked
or not.... i am not able to do that at all... i tried to create an
event handler as well but it didnot work....so this is what the
application should do...

create radio buttons dynamically in wizard sheet...
user selects a user name....
then returns the name of the user selected i.e. text of the radio
button....

not able to do that .....
sending the code...
plzzzzzzzzzzzzzzzzzzzzzz help



private string SelectUserName()
{
string name = "";
int num = 0;
num = asd.Tables["tbluser"].Rows.Count;
Array ComArray = new Array[num];

wizardSheet1 company = new wizardSheet1();
num = 15;
for (int i = 0; i < asd.Tables["tbluser"].Rows.Count; i++)
{
RadioButton rad = new RadioButton();
company.Controls.Add(rad);
rad.Location = new System.Drawing.Point(15,num);
rad.Text = asd.Tables["tbluser"].Rows[1].ToString();
//rad.Click += new System.EventHandler(checkuser());
//ComArray.c
rad.Name = "rad" + i.ToString();
num = num +30;
}

if (company.ShowDialog() == DialogResult.OK)
{
return company.CompanyName.ToString();
}
else

{
//company.
return "error";
}

}
 
J

John B

(e-mail address removed) wrote:

See Inline
I have have to check if the dynamically created radiobutton is checked
or not.... i am not able to do that at all... i tried to create an
event handler as well but it didnot work....so this is what the
application should do...

create radio buttons dynamically in wizard sheet...
user selects a user name....
then returns the name of the user selected i.e. text of the radio
button....

not able to do that .....
sending the code...
plzzzzzzzzzzzzzzzzzzzzzz help



private string SelectUserName()
{
string name = "";
int num = 0;
num = asd.Tables["tbluser"].Rows.Count;
Array ComArray = new Array[num];

wizardSheet1 company = new wizardSheet1();
num = 15;
for (int i = 0; i < asd.Tables["tbluser"].Rows.Count; i++)
{
RadioButton rad = new RadioButton();
company.Controls.Add(rad);
rad.Location = new System.Drawing.Point(15,num);
rad.Text = asd.Tables["tbluser"].Rows[1].ToString();
//rad.Click += new System.EventHandler(checkuser());


You are on the right track here, make sure that checkuser conforms to
the eventhandler delegate signature (object, eventargs)
i.e. private void CheckUser(object sender, EventArgs e)
then in the checkuser method, do this
this.CompanyName = (sender as RadioButton).Text;

HTH
JB
 
B

Bruce Wood

Well, one thing you need to change is that checkuser() shouldn't have
parentheses after it:

rad.Click += new System.EventHandler(checkuser);

So long as checkuser looks like this

private void checkuser(object sender, System.EventArgs e)
{
...
}

it should work fine. I do the same thing with dynamically generated
PictureBoxes, and it works.
 
Top