.NET

Reply
Valued Mentor
AubelecBE
Posts: 407
Registered: ‎01-27-2010
Message 1 of 6 (202 Views)

Noob with Event Help please

202 Views, 5 Replies
10-09-2012 04:35 AM

Hi, i am totaly new with Event in VB.net.

 

So : my project :

One class with a lot of collection.

 

I have a MDIFORM for show all stuff inside this class.

 

so in the class if i add a new object in a collection (ex : block) if want to raise a event .

 

The Child Form receive this event and adjust the data.

 

So for this  my code :

Inside my class :

 '-------------------------------------------------------------------------
    '------ Ajout d'un Bloc --------------------------------------------------
    '-------------------------------------------------------------------------
    ' ENTREE
    '    DefBloc : La référence du bloc à traiter (ObjectId)
    ' SORTIE
    '    Le pointeur du nouveau Bloc
    '-------------------------------------------------------------------------
    Public Function AddBloc(ByRef DefBloc As Object, ByVal Debug As Boolean) As ClassDef0f_Bloc

        Dim DefRetour As ClassDef0f_Bloc
        DefRetour = New ClassDef0f_Bloc(DefBloc(GestionAUTOCAD.Enum_GA_GSFB.Nom))
        If DefRetour.ExtractionAtt(DefBloc, Debug) = True Then
            Try
                'ajout à la collection
                DefRetour.ClassBase = Me
                cCollBloc.Add(DefRetour, DefRetour.Nom)
                'MaJ des FenetreConfig
                RaiseEvent EventBlocNew(DefRetour.Nom)
                Return DefRetour

            Catch ex As Exception
                'erreur car déjà existant
                DefRetour.Dispose()
                DefRetour = Nothing
                MsgBox("Ce nom de bloc existe déjà !", MsgBoxStyle.Information, "Erreur Utilisateur")
                Return Nothing
            End Try
        Else
            'erreur à la création
            DefRetour.Dispose()
            DefRetour = Nothing
            MsgBox("Erreur à l'extraction des attributs", MsgBoxStyle.Information, "Erreur Systeème")
            Return Nothing
        End If
    End Function

 --> i raise the évent EventBlocNew

this event is : Shared Event EventBlocNew(ByVal Nom As String)    in this class

 

So in my form :

in the new : AddHandler ClassDef0_StyleGeneral.EventBoiteOpNew, AddressOf EventBoiteOpNew

in the finalize : RemoveHandler ClassDef0_StyleGeneral.EventBoiteOpNew, AddressOf EventBoiteOpNew

 

 

 

i retrieve the event :

Protected Sub EventBlocNew(ByVal Nom As String)
        Dim columnB As Windows.Forms.DataGridViewComboBoxColumn = Nothing
        columnB= DataGridViewCalque.Columns(EnumCalque.Bloc)
        columnB.Items.Remove(Nom)
    End Sub
 

 

so all my code woks fine in the fist loaded project (in autocad)  but when i quit and launch this  the code in Protected Sub EventBlocNew(ByVal Nom As String)   crash..

--> Windows.Forms.DataGridViewComboBoxColumn --> 0 items...  

WHY !

 

i have tested the sub with a object reference of my MDIForm . (by ref F as object,)  -> so i check the num of columns and i have not 0  so     with the event i am not in the actual MDIChild Form ?

 

 

 

I dont understand this..

 

 

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 2 of 6 (148 Views)

Re: Noob with Event Help please

10-16-2012 05:51 AM in reply to: AubelecBE

Hello,

 

I suggest placing a breakpoint in the constructor and running it twice to simulate that condition.

If another instance is getting created for some reason, breakpoint in the form constructor should get hit and then you can find out from where it is getting called using the call stack.

 

Hope this helps.

 

If you can provide a minimal sample project demonstrating the behavior, I can have a look at it.

 

 

 

 



Balaji
Developer Technical Services
Autodesk Developer Network

Valued Mentor
AubelecBE
Posts: 407
Registered: ‎01-27-2010
Message 3 of 6 (127 Views)

Re: Noob with Event Help please

10-18-2012 03:38 AM in reply to: Balaji_Ram

thx. i do that.

 

I dont know why with the event i dont have th correct value of my Datagridview..

 

But i you can share your example for event. i appreciate.

thx

Valued Mentor
AubelecBE
Posts: 407
Registered: ‎01-27-2010
Message 4 of 6 (123 Views)

Re: Noob with Event Help please

10-18-2012 04:19 AM in reply to: AubelecBE

I find my little bug.

 

i have add the removehandler in my finalyse of the form but this sub is never call.

so i move it to the sub in .designer of the form see below

 

<System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                RemoveHandler ClassDef0_StyleGeneral.EventBoiteOpMaJ, AddressOf EventBoiteOpMaJ

                DefBlocEnCours = Nothing
                DefConfigEnCours = Nothing
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

 so the question how i can override this sub in my form ? i can move the sub in my form ? I cant override it.

 

How i can force autocad to pass in it ? i use form.dispose so if i use it, finalize is never call.

 

ADN Support Specialist
Balaji_Ram
Posts: 749
Registered: ‎03-21-2011
Message 5 of 6 (120 Views)

Re: Noob with Event Help please

10-18-2012 04:52 AM in reply to: AubelecBE

Glad you have found the issue.

 

How about using the FormClosing or FormClosed event to remove the handler ?

 



Balaji
Developer Technical Services
Autodesk Developer Network

Valued Mentor
AubelecBE
Posts: 407
Registered: ‎01-27-2010
Message 6 of 6 (104 Views)

Re: Noob with Event Help please

10-19-2012 03:24 AM in reply to: Balaji_Ram

i cant do that.

it is a MDI Chid so i close the form but i reopen after... or i have to add handle in open event.

yes.. i cant do that.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.