newbie: RadioButton

B

bz

Hi,

Sorry... for all these newbie questions but MSDN sucks nowaday... ;(

I have 5 groups of RadioButtons and each group has 10 buttons. There is no
control array. So, am I understanding this correctly that I need to have 5
x 10 = 50 If-Then-Else statements to check which RadioButtons are checked?

Thanks for helping!

(i.e.)

If RadioButton1.Checked = True Then...
If RadioButton2.Checked = True Then...
..
..
..
If RadioButton50.Checked = True Then...

--
There is no answer.
There has not been an answer.
There will not be an answer.
That IS the answer!
And I am screwed.
Deadline was due yesterday.

There is no point to life.
THAT IS THE POINT.
And we are screwed.
We will run out of oil soon.

http://spaces.msn.com/bzDaCat
 
H

Herfried K. Wagner [MVP]

bz said:
I have 5 groups of RadioButtons and each group has 10 buttons. There is
no control array. So, am I understanding this correctly that I need to
have 5 x 10 = 50 If-Then-Else statements to check which RadioButtons are
checked?

(i.e.)

If RadioButton1.Checked = True Then...
If RadioButton2.Checked = True Then...
.
.
.
If RadioButton50.Checked = True Then...

\\\
Private m_Group1SelectedRadioButton As RadioButton

Private Sub RadioButtonGroup1_CheckedChanged( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles _
RadioButton1.CheckedChanged, _
RadioButton2.CheckedChanged, _
RadioButton3.CheckedChanged

Dim SourceControl As RadioButton = DirectCast(sender, RadioButton)
If SourceControl.Checked Then
m_Group1SelectedRadioButton = SourceControl
End If
End Sub
///
 
B

bz

Got it. Thanks... Hmmm... But... This doesn't seem right...

Assumming I have 10 buttons in one group.
If I check one RadioButton, it will fire 2 events at the same time...
hmmm...
One for the "just" checked button. And one for the "just" unchecked button.

I will not know which event will fire first. (this may not be important)
(i.e.) The "just" unchecked button fires first? or the "Just" checked
button fires first?

In the worst case, it may (not sure) fire all 10 events at the same time...
(for unchecking the already unchecked buttons)

My old VB6 habit tells me not to put any event handler to any OptionButtons
and Checkboxes.

Is there any other way that does not require to fire any event that is used
to assign the "highlighted" RadioButton?
 
S

Stephany Young

I don't know what you're on but you sure as hell aren't making any sense.

Only ONE RadioButton in a given group can be Checked at any one time.
Therefore only 2 events will be fired - 1 for the 'uncheck' and 1 for the
'check'.

The events will NOT fire at the same time. They will fire one after the
other.

To be able to 'check' a RadioButton in a group, any other RadioButton that
is already 'checked' must become 'unchecked', therefore the 'uncheck' event
will always fire before the 'check' event. Try it and see.

Write 100 lines - I must not let my old VB6 habits influence my .NET code.


bz said:
Got it. Thanks... Hmmm... But... This doesn't seem right...

Assumming I have 10 buttons in one group.
If I check one RadioButton, it will fire 2 events at the same time...
hmmm...
One for the "just" checked button. And one for the "just" unchecked
button.

I will not know which event will fire first. (this may not be important)
(i.e.) The "just" unchecked button fires first? or the "Just" checked
button fires first?

In the worst case, it may (not sure) fire all 10 events at the same
time... (for unchecking the already unchecked buttons)

My old VB6 habit tells me not to put any event handler to any
OptionButtons and Checkboxes.

Is there any other way that does not require to fire any event that is
used to assign the "highlighted" RadioButton?
 
H

Herfried K. Wagner [MVP]

Stephany Young said:
I don't know what you're on but you sure as hell aren't making any sense.

Only ONE RadioButton in a given group can be Checked at any one time.
Therefore only 2 events will be fired - 1 for the 'uncheck' and 1 for the
'check'.

The events will NOT fire at the same time. They will fire one after the
other.

To be able to 'check' a RadioButton in a group, any other RadioButton that
is already 'checked' must become 'unchecked', therefore the 'uncheck'
event will always fire before the 'check' event. Try it and see.

.... what's the point and the relation to the code snippet I posted?! The
private variable in my code sample stores a reference to the last
radiobutton control belonging to a certain group that was selected by the
user.
 
H

Herfried K. Wagner [MVP]

Addendum:

Sorry, Stephany, my newsreader didn't show the OP's reply to my post and
displayed yours as an immediate reply to mine...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top