vs2005 - 'The event Click is read-only and cannot be changed' - What?

D

dbuchanan

Hello,

What does this error mean?
"The event click is read-only and cannot be changed"

This is a design-time error. It is displayed instead of the form.

Here is the full text
\\
"One or more errors encountered while loading the designer. The errors
are listed below. Some errors can be fixed by rebuilding your project,
while others may require code changes.

The event click is read-only and cannot be changed

at
System.ComponentModel.Design.EventBindingService.EventPropertyDescriptor.SetValue(Object
component, Object value)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAttachEventStatement(IDesignerSerializationManager
manager, CodeAttachEventStatement statement)
at
System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager
manager, CodeStatement statement)
//

I have made it go away by commenting out the following code. Then I
rebuild, close and reopen the solution.

(This is used within an inherited form thus the Overrides.)
\\
Protected Overrides Sub btnOK_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnOK.Click

'Save to Quote table
InsertIntoQuote()
'UpdateDatasourceTable(_dataSet1.tbl010Quote)

'Save to Version table
insertIntoVersion()
'UpdateDatasourceTable(_dataSet1.tbl020Version)

Me.Close()
End Sub
//

What is the problem?

dbuchanan
 
C

Cor Ligthert [MVP]

dbuchanan,
What does this error mean?
"The event click is read-only and cannot be changed"
One or more errors encountered while loading the designer. The errors
are listed below. Some errors can be fixed by rebuilding your project,
while others may require code changes.

Have a look at the code in the designerpart, most probably did you change or
delete something in that.
(This can even be because you deleted a class by instance a strongly typed
dataset from your solution explorere).

I hope this helps,

Cor
 
D

dbuchanan

Cor,

There you go guessing :)

Please read my posts carefully before responding :)

I said
I have made it go away by commenting out the following code. Then I
rebuild, close and reopen the solution.

How coud that work if I had changed or deleted code or deleted a class?

The problem does come back, but not on the first time I run it after
the steps above. It will seem to work okay on the first or second
running, but then it will fail again. The same steps will temporarly
recover the problem, but the problem *will* return.

Anybody have any suggestions regarding why commenting the following
code would temporarly remedy the problem

\\
Protected Overrides Sub btnOK_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnOK.Click

'Save to Quote table
InsertIntoQuote()
'UpdateDatasourceTable(_dataSet1.tbl010Quote)

'Save to Version table
insertIntoVersion()
'UpdateDatasourceTable(_dataSet1.tbl020Version)

Me.Close()
End Sub
//

Thank you,
dbuchanan
 
C

Cor Ligthert [MVP]

Copied text until the next line
--------------------------------------------------------------
This is used within an inherited form thus the Overrides.)
\\
Protected Overrides Sub btnOK_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnOK.Click

'Save to Quote table
InsertIntoQuote()
'UpdateDatasourceTable(_dataSet1.tbl010Quote)

'Save to Version table
insertIntoVersion()
'UpdateDatasourceTable(_dataSet1.tbl020Version)

Me.Close()
End Sub
//

What is the problem?
------------------------------------------
Problem is probably your "thus". What are you overriding.

This is overriding a btnOK which is probably nowhere created in this class,
not even in your designer part. However AFAIK you are not even able to do
that, what is the reference you had that this is "thus".

Cor.
 
B

Bart Mermuys

Hi,

dbuchanan said:
Cor,

There you go guessing :)

Please read my posts carefully before responding :)

I said

How coud that work if I had changed or deleted code or deleted a class?

The problem does come back, but not on the first time I run it after
the steps above. It will seem to work okay on the first or second
running, but then it will fail again. The same steps will temporarly
recover the problem, but the problem *will* return.

Anybody have any suggestions regarding why commenting the following
code would temporarly remedy the problem

\\
Protected Overrides Sub btnOK_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnOK.Click
----------------------
This looks suspicious.

If the base clase already handles the btnOK.Click event, eg:

Partial Public Class BaseForm
Protected Overridable Sub btnOK_Click(
ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnOK.Click
----------------------
' .... code ...
End Sub
End Class

Then the derived class does not need to handle the event ("Handles"), only
override it, eg:

Partial Public Class DerivedForm
Protected Overridable Sub btnOK_Click(
ByVal sender As System.Object,
ByVal e As System.EventArgs)

' ... code that runs before base.btnOK_Click here ...

MyBase.btn_OK_Click(sender, e)

' ... code that runs after base.btnOK_Click here ...
End Sub
End Sub

In this example the base class handles the event while the derived class
only overrides it (doesn't handle it again).

If you do handle the event in both the base form and derived form and
override it then this would not cause an Exception but would cause the
eventhandler to fire twice.

The Exception is most likely caused because the btnOK (in the base class)
has no 'protected' Modifier(see btnOK properties) and therefore you can't
add events in the derived class (in VB.Net terms doesn't allow you to use
"Handles"). BUT as explained earlier you probely don't need this event
handling in the derived class because you are already overriden it.


HTH,
Greetings
 
D

dbuchanan

Bart,

The exception is not caused because of the modifier because the base
class is modified as "Protected", however I need to remove the "Handles
btnOK.Click" from the derived class code.

I'll try that and see if I get any errors.

Thank you,
dbuchanan
 
B

Bart Mermuys

Hi,

dbuchanan said:
Bart,

The exception is not caused because of the modifier because the base
class is modified as "Protected",

Strange, i hope you double checked, anyways at least the oposite is true, if
you Handle an event in a derived form of a base form's Control whose
Modifiers is set to friend, the designer will show the exact same exception.
however I need to remove the "Handles btnOK.Click" from the derived class
code.

Yes, if you use Overridable-Overrides then you only have to Handle the event
once, eg. in the base Form.

Greetings
 
D

dbuchanan

Hello Bart,

when I said...
I had misunderstood you. I thought you meant the code as in "Protected
Overridable Sub".
Now I know you meant the modifier in the properties of the button. Yes
it was "Friend". (!)

And now I think I know why the error was "Click is read-only" though it
certainly isn't very clear.

Thanks again,
dbuchanan
 
B

Bart Mermuys

Hi,

dbuchanan said:
Hello Bart,

when I said...

I had misunderstood you. I thought you meant the code as in "Protected
Overridable Sub".

no no :)
Now I know you meant the modifier in the properties of the button. Yes
it was "Friend". (!)

So that was causing the problem then (together with handling the button
event in the derived form).
And now I think I know why the error was "Click is read-only" though it
certainly isn't very clear.

You should also notice that when a base form control modifiers is set to
'Friend' that all properties and events for that control on the derived form
inside the properties window are shown grayed-out, meaning you can't use
them.

But, you can add "Handles" in code, next time you compile and open the
designer, the designer throws because it's trying to change the text of a
grayed-out (readonly) event (in properties window).
Thanks again,

You're welcome.
Greetings
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top