Handles Mix

L

lmefford

Ok, so I've got a weird question. I'm working with an outside class
that someone made that will save the application settings in the
Application Data Folder. However, one problem I'm having, and I
already found the (lengthy) fix for is that I'm not able to mix
handles:

Private Sub uicheck1_CheckedChanged _
(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _
uicheck1.CheckedChanged, _
uicheck2.CheckedChanged, _
uicheck3.CheckedChanged, _
uitext1.TextChanged

What happens when I run my code like that, it won't run the portion to
save whatever check boxes are checked, however; it saves the changed
text in my textbox just fine. Is there something that I'm missing
here, because when I remove the uitext1.textchanged, it works
perfectly fine. The problem with that is that I'm kind of wanting to
cut down on the code on this part of the app since it's a bit silly to
copy and paste my saving and loading code several times.
 
G

Guest

lmefford,

The one handler can handle the checkbox checkedchanged and textbox
textchanged for any number of checkbox and textbox controls. So that is not
the problem.

Perhaps the code in the handler is the problem.

Kerry Moorman
 
G

Guest

Create either two handlers, one for each class (checkboxes, textboxes), or
create four, one for each object. Each handler can then call a common
subroutine where the handler you wanted resides.
 
L

lmefford

lmefford,

The one handler can handle the checkbox checkedchanged and textbox
textchanged for any number of checkbox and textbox controls. So that is not
the problem.

Perhaps the code in the handler is the problem.

Kerry Moorman

Private Sub SaveCheckBoxes(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles _
uicheck1.CheckedChanged, _
uicheck2.CheckedChanged, _
uicheck3.CheckedChanged
Dim ccontrol As Control
Dim chk As CheckBox
Dim txt As TextBox
For Each ccontrol In Me.Controls
If (TypeOf ccontrol Is CheckBox) Then
chk = DirectCast(ccontrol, CheckBox)
a.SaveSetting(chk.Name.ToString, chk.Checked.ToString)
End If
Next
End Sub

That's essentially what it is. Throw in the textbox handle and an if
statement for if the control is a textbox, and that's what it is. It
works perfectly if you seperate them and the text works fine if you
add them. I'm not sure why it does that and it doesn't make much sense
why it wouldn't work that way.
 
S

Stephany Young

If you really want some help then posting what 'essentially what it is' cuts
no ice. You need to post 'exactly what it is'.

However, in your 'sample', do you really want information about ALL CheckBox
controls on the form saved when you change the Checked state of one Checkbox
control?

As to mixing control events to a single handler, you need to realise that
The TextBox.TextChanged event is raised every time you type a character in
the TextBox control. Given that one can write one's life story in a TextBox
control, would you really want the application settings to be saved for
EVERY individual key press?
 

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