Results 1 to 3 of 3

Thread: Panel with RadioButtons Disappearing from GUI

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    23

    Panel with RadioButtons Disappearing from GUI

    Hi,

    I have a panel on my GUI with radio buttons. When I run the code to determine which is the checked radio button from that panel, the code runs fine, but the panel disappears from the GUI after that.

    Here is the code I have to determine the checked radio button:
    Code:
    Dim rbName = (From r As RadioButton In Panel1.Controls.OfType(Of RadioButton)() Where r.Checked Select r.Name)
    System.Console.WriteLine(rbName.First)
    I have tried using:
    Panel1.Visible = True

    and also
    Panel1.Show()
    Panel1.Refresh()

    but it doesn't show the panel again. I tried the same thing for individual radio buttons such as RadioButton1.Visible = True and it doesn't work. I would appreciate any help with showing the panel again on the GUI!

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Panel with RadioButtons Disappearing from GUI

    Something else must be going on to make the panel not shown. In the attach VS2008 project you get to select a radiobutton selection from a choice of three using two methods, one with a language extension while the other does the same thing simply inline code.

    In short using your code or the following will not make a form panel disappear

    Code:
                Dim RB = (From Item In (From Control In Panel1.Controls _
                                        Where TypeOf Control Is RadioButton _
                                        Select Control).Cast(Of RadioButton)() _
                                        Where Item.Checked _
                                        Select Item).DefaultIfEmpty(New RadioButton).First
    
                If RB.Name = String.Empty Then
                    MsgBox("No card selected")
                Else
                    MsgBox(String.Format("Pay with [{0}]", RB.Text))
                    ReSetPanelRadioButtons()
    Same as above but in an extension
    Code:
        <System.Diagnostics.DebuggerStepThrough()> _
        <System.Runtime.CompilerServices.Extension()> _
        Public Function SelectedRadioButton(ByVal container As Control) As RadioButton
    
            Return (From Item In (From Control In container.Controls _
                                        Where TypeOf Control Is RadioButton _
                                        Select Control).Cast(Of RadioButton)() _
                          Where Item.Checked _
                          Select Item).DefaultIfEmpty(New RadioButton).First
    
        End Function
    And the following mimics TryParse
    Code:
        <System.Diagnostics.DebuggerStepThrough()> _
            <System.Runtime.CompilerServices.Extension()> _
            Public Function Get_SelectedRadioButton(ByVal container As Control, _
                                                   ByRef Button As RadioButton) As Boolean
            Dim Result As Boolean = False
    
            Dim RadioCollection = From Control In container.Controls _
                                  Where TypeOf Control Is RadioButton Select Control
    
            If Not RadioCollection Is Nothing Then
                Dim CheckedButton = (From Item In RadioCollection.Cast(Of RadioButton)() _
                                     Where Item.Checked).DefaultIfEmpty(Button).First
    
                If Not CheckedButton.Name.Equals(Button.Name) Then
                    Button = CheckedButton
                    Result = True
                End If
            End If
    
            Return Result
    
        End Function
    Last edited by kareninstructor; Aug 11th, 2011 at 07:58 AM.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Sep 2010
    Posts
    23

    Re: Panel with RadioButtons Disappearing from GUI

    Thanks for your help Kevin. I did have another issue and I figured out what was wrong. But I still really appreciate your feedback!

Posting Permissions

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



Click Here to Expand Forum to Full Width