.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Noob with Event Help please

5 REPLIES 5
Reply
Message 1 of 6
AubelecBE
394 Views, 5 Replies

Noob with Event Help please

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..

 

 

5 REPLIES 5
Message 2 of 6
Balaji_Ram
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

Message 3 of 6
AubelecBE
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

Message 4 of 6
AubelecBE
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.

 

Message 5 of 6
Balaji_Ram
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

Message 6 of 6
AubelecBE
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost