Click here to Skip to main content
16,014,677 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello sir,

I am doing one windows application .I have a panel in the form.
i have want to add dynamically radio buttons in the panel left and right.
i added 4 radio buttons left and how to add right.


hr         dfsdfwewr
finance    dfdsfdfsd
accounts   abcddddsd

In a panel i want to add radio button like this.
i added 4 buttons left but next 4 button want to come righ tside how to do?


my coding

void addRadiobutton()
        {
            try
            {
                DataTable dt = new DataTable();
                dt = RoleSecurity.getRoleId();

                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    RadioButton rdo = new RadioButton();
                    rdo.AutoSize = false;
                    rdo.Height = 20;
                    rdo.Width = 215;
                    rdo.Padding = new Padding(-10);

                    if (i == 4)
                    {
                        rdo.Location = new Point(235, 28);
                    }
                    else if (i > 4)
                    {
                        rdo.Location = new Point(235, rdo.Location.Y + 25 * i);
                    }
                    else
                    {
                        rdo.Location = new Point(6, rdo.Location.Y + 25 * i);
                    }

                    rdo.Font = new System.Drawing.Font(new FontFamily("Mangal"), 9, FontStyle.Bold);
                    rdo.Text = dt.Rows[i]["Rolename"].ToString();
                    pnlRole.Controls.Add(rdo);
                    rdo.CheckedChanged += new EventHandler(radiobuttonchecked);
                }
            }


in that am getting wrongly.how to correct that?

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 27-May-12 21:05pm
v2

1 solution

That code is a bit unusual.
I would do it this way:
C#
int yLoc = 28;
int xLoc = 6;
for (int i = 0; i < dt.Rows.Count; i++)
    {
    RadioButton rdo = new RadioButton();
    rdo.AutoSize = false;
    rdo.Height = 20;
    rdo.Width = 215;
    rdo.Padding = new Padding(-10);

    if (i == 4)
        {
        yLoc = 28;
        xLoc = 235;
        }

    rdo.Location = new Point(xLoc, yLoc);
    yLoc += 25;

    rdo.Font = new System.Drawing.Font(new FontFamily("Mangal"), 9, FontStyle.Bold);
    rdo.Text = dt.Rows[i]["Rolename"].ToString();
    pnlRole.Controls.Add(rdo);
    rdo.CheckedChanged += new EventHandler(radiobuttonchecked);
    }


[edit]Dunno how, but "<" changed to "<<", Fixed - OriginalGriff[/edit]
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900