CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Add controls from one panel to the other

  1. #1
    Join Date
    Feb 2012
    Posts
    46

    Add controls from one panel to the other

    Code:
    class AllUsers
    public void AllUsers_Load(object sender, EventArgs e)
            {
                new Insert().InsertMe();
            }
    
    //==================================================================
    
    public class Insert : Linkwindow{
            int checkBoxCount = 0;
            public void InsertMe()
            {
                 if (personPanel.Controls != null)
                {
                    Control control = new Control();
                    if (control.GetType() == typeof(RadioButton))
                    {
                            foreach (RadioButton radios in rolePanel.Controls)
                            {
                                new AllUsers().allPersonPanel.Controls.Add(radios);
                            }
                        }
                    }
             }  
        }
    I created 2 panels in 2 different forms to add controls from the personPanel(which pulls it items from the database) to allPersonPanel but to my surprise the code does not seem to achieve this purpose, what should I do? Thanks. God bless in Jesus name.

  2. #2
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,539

    Re: Add controls from one panel to the other

    Code:
    class AllUsers{ // Ok you are un class AllUsers
         public void AllUsers_Load(object sender, EventArgs e)
        {
        // Here you are creating a totally other class 
        // This class has no link to the other class so itt could know 
        // its parent in any way ???
          new Insert().InsertMe(); // btw its not a static method
         }
     
    //==================================================================
     
    public class Insert : Linkwindow{ // Ok here is the class as we can see
        int checkBoxCount = 0;
       public void InsertMe()
        {
         if (personPanel.Controls != null) // which PersonPanel are you talking about ?? Is is creted ianywhere in this class - No 
         {
          Control control = new Control(); // This is a totally new Control, its undefined what type of control it will be its an object only of baseClass Control
           if (control.GetType() == typeof(RadioButton)) // it cannot be a Radiobuuon it was just created and has no other defined type then Control
               {
               foreach (RadioButton radios in rolePanel.Controls)
             // you are not linked to any rolePanel in that class
               {
                    new AllUsers().allPersonPanel.Controls.Add
    (radios); // You are creating a separate AllUsersPanel in that class and would add radiobuttons to this Class -- no problem while you never reach that code it will not happen 
               }
           }
       }
     } 
    }
    Sorry I'm a bit of sarcastic because when I wanted to show you how to do instead of doing my advice you simple create a new post
    I have already told you to show the project including all af your self created Controls so I can get apicture of it and beeing able to clear up your misunderstoods pointing you to different problems and showing you solutions to do it. This would be teaching and there is no way out - you need to learn that things like using classes in classes, ways of linking them together all that
    For a short brief example To be able to point back to a parent class within the InsertClass do like the following
    Code:
    class AllUsers: Users  { // create an abstract  class Users as where you may derive AllUsers from it
         private InsertClass  _insert;
          public void AllUsers_Load(object sender, EventArgs e)
          {
     
    // This class has to know its parent
                    _insert= new InsertClass(this)
     
                   _insert.InsertMe();
           }     
    }
     
    //And your class Insert needs a constructor like
    public class Insert{
          private  Users _user;      
           //constructor
           public Insert(Users user){
              _user = user;
          }
        // This allows you to adress the AllUsers class directly drom this 
        // class without getting in problems like trying to create again 
        //   an Allusers class inside here, which is an unworkable attempt
    }
    Here is nearly the same question some posts before

    http://www.codeguru.com/forum/showthread.php?t=521462

    Please stay in your Thread until it is really resolved !!! Dont permanently create a new thread when the old o talks about the same problem
    Last edited by JonnyPoet; March 20th, 2012 at 09:37 AM.
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  3. #3
    Join Date
    Feb 2012
    Posts
    46

    Thumbs up Re: Add controls from one panel to the other

    Code:
    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);
                        }
                    }
                }
            } 
    
    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));
                    }
                }    
          }
    Thanks sir I have replied the previous emails.
    1. To continue from where I stopped, I troubleshooted this code and it actually shows the text of each checkbox selected. kudos for your great support. My new step to is that i want to add the radioperson(persons) from the personpanel on the linkUser form page to allPersonPanel in allusers form page, like i wrote it in the last foreach statement but it is not working, it does not show. In what best way can I achieve that?

    2. items.Checked.GetHashCode();
    rolePanelAdd();
    This code is not best written, I want your professional instructive support. What I truly want to achieve from this is this: A person(radio button) is selected on the personPanel in linkUser form. if Checkboxes are selected from rolePanel then I want it to assign every selected checkbox to the selected person. Now assuming persons(radio buttons) are now showing on allPersonPanel in the AllUser form, when I click on the person it should display the selected role of that person in allrolePanel of the AllUser. Thanks sir.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)