3 Replies - 4738 Views - Last Post: 23 March 2012 - 05:47 PM Rate Topic: -----

#1 ken2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 05-December 10

assigning values to a radiobutton click

Posted 23 March 2012 - 09:38 AM

 public void linkUser_Click(object sender, EventArgs e)
        {
            if (personPanel.Controls != null)
            {
                foreach (RadioButton items in personPanel.Controls)
                {
                    new AllUsers().allPersonPanel.Controls.Add(((RadioButton)items));
                    //string str = (((RadioButton)items)).Text;
                    //MessageBox.Show(str);
                }
                AllUsers all = new AllUsers();
                all.Show();


Please how do I add controls from one panel on a form to another panel in another form? I use the messageBox to troubleshoot this and it pulls the text into it but when I add it directly to the to the allPersonPanel in the AllUsers form it does not appear, what should I do?

Is This A Good Question/Topic? 0
  • +

Replies To: assigning values to a radiobutton click

#2 ken2010  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 05-December 10

Re: assigning values to a radiobutton click

Posted 23 March 2012 - 11:29 AM

public void rolePanelAdd() {
            if (rolePanel.Controls != null)
            {
                foreach (CheckBox checkRole in rolePanel.Controls)
                {
                    if (checkRole.Checked == true)
                    {
                        string str = (((CheckBox)checkRole)).Text;
                        MessageBox.Show(str);
                        //if (checkRole.Controls.Count > 0)
                        //{
                        //    for (int i = 0; i < checkRole.Controls.Count; i++)
                        //    {
                        //        string[] s = new string[i];
                        //        stringBuilder.Append(s[i]);
                        //        stringBuilder.Append("\n");
                        //        newArray.Add(stringBuilder);
                        //    }
                        //    MessageBox.Show(newArray.ToString());
                        //}
                    }
                }
                //MessageBox.Show(stringBuilder.ToString());
            }
        }
        public void personRadio_CheckChanged(object sender, System.EventArgs e) {
            RadioButton personRadio = (RadioButton)sender;
        }

        public void linkUser_Click(object sender, EventArgs e)
        {
            if (personPanel.Controls != null)
            {
                foreach(RadioButton items in personPanel.Controls){
                    items.Checked.GetHashCode();
                    rolePanelAdd();
                }
                foreach (RadioButton items in personPanel.Controls)
                {
                    new AllUsers().allPersonPanel.Controls.Add(((RadioButton)items));
                    //string str = (((RadioButton)items)).Text;
                    //MessageBox.Show(str);
                    AllUsers all = new AllUsers();
                    all.Show();
                }
   
               
                ////var ef=new Linkwindow().linkUser_Click(sender, e);
                //f = ef;
                //ArrayList newArray = new ArrayList();
                //StringBuilder stringBuilder = new StringBuilder();
            }    
      }


All is working but not giving the desired output. What I want is that the checkedboxes checked should be displayed in the messagebox when the right radiobutton is selected in allPersonPanel. So that it will be that all radiobuttons will have checkboxes assigned to them and this will be stored as the value for each radiobutton. Please kindly help.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,199
  • Joined: 02-June 10

Re: assigning values to a radiobutton click

Posted 23 March 2012 - 05:36 PM

There are just so many things wrong with this...

But most important is concept. You can't have a control be on two forms at the same time. A control on one form cannot also be .Added to another form. Just like things in the physical world, coding objects can't be in two places at the same time.

Line 7 If it if did come close to working, you are attempting to make a new instance of an AllUsers class on every loop... Then you do nothing with it, don't add it to a collection... So it goes out of scope and is automatically .Displose()'d of at the end of the code block. Its what we call "scope". A thing exists between the {} it was created in. So if you make a thing with a for{} loop, that's its scope. If you want to access a thing for the entire class, then define it in the class braces

class someClass
{
   int yogi = 5; // Accessible to the class
   
   void someMethod
   {
        int booboo = 3; // Accessible to the method

        while(true)
        {
           string Ranger = "Smith"; // Accessible to the loop
        }
   }
}


Then again on line 11 you make a new instance of an AllUsers class and show it. Well its a new instance: So it only holds whatever the default state is.

Just stop. You need to re-read whatever book chapter you're working on regarding classes, instances and scope. Without a proper understanding of the concepts you'll never be able to write working code that USES those concepts.

This post has been edited by tlhIn`toq: 23 March 2012 - 05:36 PM

Was This Post Helpful? 1
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5676
  • View blog
  • Posts: 12,199
  • Joined: 02-June 10

Re: assigning values to a radiobutton click

Posted 23 March 2012 - 05:47 PM

What? Huh?

You can't display a checkbox in a messagebox. You can state whether or not it is checked. But you can't just stick an entire CheckBox object into a messagebox. All you can do is provide a message (text) in a MessageBox.

You could set the Message to read "is checked" or "is NOT checked" and the caption to be the name of the Checkbox.

You could create a text that is a list of all the checkboxs and their statuses.

40 new AllUsers().allPersonPanel.Controls.Add(((RadioButton)items));

You cannot add a control from one form to another. YOu already have a thread open for this. I'll merge them since they seem to be the same topic.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1