multiple panels multiple radio buttons one group!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DragonLord
    New Member
    • Mar 2007
    • 122

    #1

    multiple panels multiple radio buttons one group!

    Ok here is the situation in detail.

    Single form with multiple items on it, 4 of which are panls that contain radio butons. Each panel loads it's radio buttons from a list of items in a sql database table.

    This is the easy part.

    Hard part is this. The panels are not ll in a row on the form so i can't just put the into a single group box yet I want them all to behave as one.

    Is there a way that I can programtically tell this windows form that all these radio buttons belong to the same group and while they are seperated by (sub groups i.e. panels) only one option can be selected among the four panels.

    Please help I have tried many google searches with no results.
  • kurtzky
    New Member
    • Nov 2008
    • 26

    #2
    can you post the screen shot of your form design here? You need to do some Control manipulation. I think i can help you with that, it just so happen that I can't picture out how it should really work.. :D

    Comment

    • DragonLord
      New Member
      • Mar 2007
      • 122

      #3
      Ok here is the screenshot, I moved around the panels to play with a group box out of desperation.

      here is the code for the loading of the panels.

      Code:
      private void BuildRadioButtonPanel(int numColumns, int leftOffset, int topOffset, int myPanel)
              {
                  List<RadioButton> RadioButtonList = null;
                  int NumColumns;
                  int NumRows;
                  int TopOffset;
                  int LeftOffset;
                  Point StartPosition;
                  Point CurrentPosition;
                  IEnumerator RadioButtonIter;
      
                  //NumColumns = 3;
                  //TopOffset = 25;
                  //LeftOffset = 204;
                  NumColumns = numColumns;
                  TopOffset = topOffset;
                  LeftOffset = leftOffset;
                  //Get the list of checkboxes from the database.
      
                  switch (myPanel)
                  {
                      case 1:
                          {
                              RadioButtonList = _newDBCourierReq.LoadRadioButtons("ItemListsGetDescSub_ID", "@GroupType", 9, "@SubGroupType", 10);
                              break;
                          }
                      case 2:
                          {
                              RadioButtonList = _newDBCourierReq.LoadRadioButtons("ItemListsGetDescSub_ID", "@GroupType", 9, "@SubGroupType", 11);
                              break;
                          }
                      case 3:
                          {
                              RadioButtonList = _newDBCourierReq.LoadRadioButtons("ItemListsGetDescSub_ID", "@GroupType", 9, "@SubGroupType", 12);
                              break;
                          }
                      case 4:
                          {
                              RadioButtonList = _newDBCourierReq.LoadRadioButtons("ItemListsGetDescSub_ID", "@GroupType", 9, "@SubGroupType", 13);
                              break;
                          }
                      case 5:
                          {
                              RadioButtonList = _newDBCourierReq.LoadRadioButtons("ItemListsGetDescSub_ID", "@GroupType", 9, "@SubGroupType", 15);
                              break;
                          }
                  }
      
      
                  //Determine the number of rows needed to display all the checkboxes.
                  NumRows = Convert.ToInt32((RadioButtonList.Count / NumColumns));
      
                  //Set the starting point to add the checkboxes to the panel
                  StartPosition = new Point(2, 2);
                  //MessageBox.Show(NumRows.ToString());
      
                  //If the number of columns is not exactly equal to a multiple of the number
                  //of columns in the panel then add an extra row for the strays.
                  if (RadioButtonList.Count % NumColumns != 0)
                  {
                      NumRows = NumRows + 1;
                  }
      
                  RadioButtonIter = RadioButtonList.GetEnumerator();
                  //Set the current position of the checkBox
                  CurrentPosition = new Point(StartPosition.X, StartPosition.Y);
      
                  for (int ICrntRow = 1; ICrntRow <= NumRows; ICrntRow++)
                  {
                      //Add the Checkboxes to the current Row
                      for (int ICrntCol = 1; ICrntCol <= NumColumns; ICrntCol++)
                      {
                          //Add the checkboxes to the Row based on the required number of columns.
                          if (RadioButtonIter.MoveNext())
                          {
                              //Find the Current Checkbox and set its size and location properties.
                              RadioButton thisRadioButton = (RadioButton)RadioButtonIter.Current;
                              switch (myPanel)
                              {
                                  case 5:
                                      {
                                          thisRadioButton.Size = new Size(150, 19);
                                          break;
                                      }
                                  default:
      
                                      thisRadioButton.Size = new Size(200, 19);
                                      break;
                              }
                              thisRadioButton.Font = new Font("Microsoft Sans Serif", 9);
                              thisRadioButton.Location = CurrentPosition;                        
                              
                              thisRadioButton.CheckedChanged += new System.EventHandler(RBs_CheckedChanged);
                              //Add the checkboxes to the panel control
                              switch (myPanel)
                              {
                                  case 1:
                                      {
                                          
                                          pRegularServices.Controls.Add(thisRadioButton);
                                          break;
                                      }
                                  case 2:
                                      {
                                          
                                          pInTownExpress.Controls.Add(thisRadioButton);
                                          break;
                                      }
                                  case 3:
                                      {
      
                                          pUSA.Controls.Add(thisRadioButton);
                                          break;
                                      }
                                  case 4:
                                      {
      
                                          pInternational.Controls.Add(thisRadioButton);
                                          break;
                                      }
                                  case 5:
                                      {
      
                                          pCanadaPost.Controls.Add(thisRadioButton);
                                          break;
                                      }
                              }
      
                            //  CourierServiceGroupBox.Controls.Add(thisRadioButton);
                              CurrentPosition.X += LeftOffset;
      
      
                          }
                      }
                      //Advance To the next row
                      CurrentPosition.Y += TopOffset;
                      CurrentPosition.X = 2;
                  }
                  //foreach (Control x in this.pMain.Controls)
                  //{
                  //    MessageBox.Show(x.Text);
                  //}
                 
                 // CourierServiceGroupBox.Controls.Add(pRegularServices);
                 // CourierServiceGroupBox.Controls.Add(pInTownExpress);
              }
      Attached Files

      Comment

      • kurtzky
        New Member
        • Nov 2008
        • 26

        #4
        so far i can't figure out the answer, but maybe you can try putting the same tag on the panels that you want to function as one.

        Comment

        Working...