|
-
Apr 2nd, 2004, 06:16 PM
#1
Thread Starter
Junior Member
RadioButton selection problem through code with multiple groups
Hi,
I have created 2 radio button groups with multiple buttons to show/store Gender & Preferred Contact Method. I Use two seperate fields in Access DB for each group. First field can be "F" or "M", second field can be "H", "W", "M",.. etc. When I pull the record from the DB, I select the appropriate radio button according to the field values. When I do the selection from the GUI, I am able to select one item from each group, but when I do it through the code, it clears out the first selection:
Code:
Private Sub ShowRadioButtons()
Select Case editGender.Text
Case "M"
RadioButtonGenderM.Select()
Case "F"
RadioButtonGenderF.Select()
End Select
Select Case editPreferred.Text
Case "W"
RadioButtonW.Select()
Case "H"
RadioButtonH.Select()
Case "M"
RadioButtonM.Select()
Case "F"
RadioButtonF.Select()
Case "P"
RadioButtonP.Select()
Case "O"
RadioButtonO.Select()
Case "E"
RadioButtonE.Select()
End Select
End Sub
If I swap two select statements, always one item from the second select statement is selected. I tried grouping the buttons in two panels and two groups boxes and both give the same error.
Any idea?
-
Apr 2nd, 2004, 07:33 PM
#2
PowerPoster
Hi,
If you have several RadioButtons in the same GroupBox, you can only select one.
If you split the radiobuttons into two groupboxes you WILL be able to select one from each groupbox.
If you cannot do this, then you have not correctly placed the radiobuttons int two separate groupboxes.
If you used cut & copy then you should be OK but if you tried to drag and drop, you may have made a mistake.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Apr 2nd, 2004, 09:36 PM
#3
Thread Starter
Junior Member
Thanks for the quick reply. I grouped the buttons in two seperate groups. The problem is that I can select any one button from each group using the mouse. But the code above selects only the last select statemet (Second select group). If I swap two select groups or copy the first select statement after the second one, again, only the last select group works.
I also tried copy/paaste into two different groups and had the same problem. Creating a new form, two groups with two button each and selecting one button from each group in formload event works OK. Really confused????
-
Apr 3rd, 2004, 03:42 AM
#4
PowerPoster
Hi
If you really mean
"I also tried copy/paaste into two different groups and had the same problem. "
Then that is your problem. You should CUT & Paste. You MUST delete (Cut) the existing radioButtons BEFORE you paste them.
If that is not the problem, make sure you are pasting them correctly into the new groupbox.
One other thought. Are you trying to handle all the radiobutton.select events in a single event handler?
"Creating a new form, two groups with two button each and selecting one button from each group in formload event works OK. Really confused????"
Why select them in the formload event? Why not select them normally.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Apr 3rd, 2004, 04:18 PM
#5
Thread Starter
Junior Member
Taxes,
I deleted all the buttons and two panels and recreated them from the toolbox, still have the same problem. I believe the problem you are thinking is not to be able to seperate two groups. However, in my case the groups can be differentiated but selecting them within the code has a problem. If the copy/cut/paste creates a problem, two groups would not act in mutually exlusive way using the mouse/GUI. But it is perfectly OK to select one item from each group via the GUI (mouse clicks).
I do not have any event handler for the buttons at all.
Selecting a formload event simulates the way I implement it in the actual program. As I briefly explained above, With the form load event, I load a selected record data from the database into ~25 textboxes using data binding. Then I translate two fields' information into radiobutton representation using calling the "ShowRadioButtons()" procedure which I give the code above. For some reason, it acts as if there was only one (last) select case statement and after the form loads I can see only one button selected in one group.
-
Apr 3rd, 2004, 06:45 PM
#6
PowerPoster
Hi,
I have tried out what you are doing and I'm afraid I get the same result as you. It must be that the RadioButton is intended to respond properly only to the mouse click. The way you are using it is a bit wierd, as by it's very naturethe RadioButton is there for the user to select with the mouse. Try replacing
RadioButtonGenderM.Select()
with a call to the action you want to happen
May be someone else has a comment on this.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Apr 4th, 2004, 12:57 AM
#7
Thread Starter
Junior Member
Now I found the solution:
Replaced the method with property assignment i.e.:
RadioButtonGenderM.Checked = True
in the select statement.
However, I also found few strange things before I found the final workaround and I like to share it with the community:
1. If I display a msgbox before button initialization, the original code works OK. See the code below. I then dig more into it and created a new form activate event and called ShowRadioButtons() in that event. After you run the code, buttons are not selected but you switch to another form and switch back to the previous form again and you get your buttons properly selected. Obviously, this is not a neat way of fixing the problem.
2. The buttons had the "FlatStyle" property as "System" (XP style). I then changed the propery to "Standard" (default) and none of the buttons were selected this time. With the "System" value, at least one set of groups was working.
Code:
Private Sub ContactEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("x")
If gContactEditUpdate Then
OleDbConnection1.ConnectionString = gConnectionString
OleDbSelectCommand1.CommandText += " WHERE(ContactID = " & gSelectedContactID & ")"
btnLoad.PerformClick()
ShowRadioButtons()
btnLoad.Visible = False
btnAdd.Visible = False
DisplayDetailsEdited = True
Else
btnAdd.PerformClick()
btnLoad.Visible = False
btnAdd.Visible = False
DisplayDetailsEdited = False
End If
End Sub
-
Apr 4th, 2004, 07:18 AM
#8
PowerPoster
Hi,
"Replaced the method with property assignment i.e.:
RadioButtonGenderM.Checked = True
in the select statement."
Are you sure? I tried that before my previous post and it did not cure the problem.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|