Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 203083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:20:49+00:00 2026-05-11T17:20:49+00:00

I have a partial class in VB.NET. Half of it is auto generated by

  • 0

I have a “partial” class in VB.NET. Half of it is auto generated by a code generation tool. That half implements INotifyPropertyChanged, so any properties in that part of the partial class raise the PropertyChanged event.

In my “custom” part of the class, I declare another property that depends on one of the properties in the auto-generated side. Therefore, when that auto-generated property changes, I also want to raise a PropertyChanged event on my custom property that depends on it.

If I go into the generated part of the class and raise the event there, that will get overwritten if I ever re-generate that part, so I don’t want to do that. I would rather add an event handler in my side of the partial class that checks if the generated property changed, and if so, raise another event for my custom property.

I’m trying to write this to hook my own event, but it’s not working:

Private Sub MyProperty_PropertyChangedHandler( _
        ByVal sender As Object, ByVal e As PropertyChangedEventArgs _
        ) Handles Me.PropertyChanged
    Select Case e.PropertyName
        Case "AutoGenProperty"
            RaiseEvent PropertyChanged(Me, _
                New PropertyChangedEventArgs("MyProperty"))
    End Select
End Sub

I’m assuming it’s because normally you’d use the WithEvents keyword to tell the compiler that you’re subscribing to events from that object. I don’t have a clue how to do this inside of the class that’s actually raising the event, or if that’s even possible.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:20:50+00:00Added an answer on May 11, 2026 at 5:20 pm

    In your constructor, you need something on the lines of

    AddHandler PropertyChanged, addressof MyProperty_PropertyChangedHandler
    

    and remove the “Handles Me.PropertyChanged” from your event handler, basically your adding the event handler manually

    where “PropertyChanged” is the name of the event you want to catch.

    UPDATE

    You can’t do that because the the ctor is in the auto generated portion of the class.
    So you can use the following idiom to add the handler for you.
    You’re going to specify a private class inside your class, and put it on as a private member on your new class, when the private member is constructed you add the handler for the event.

    Public Partial MyClass
        private class MyInitialiser
           public sub new(byval myParent as MyClass)
              Addhandler myParent.PropertyChanged, addressof myParent.MyProperty_PropertyChangedHandler
           end sub
        end class
        private _myInitialiser as new MyInitialiser(me)
    . . .
    End Class
    

    The above is untested, but I’ve done this lots of times before.

    Hope it helps 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .net application (c#) that goes something like this public partial class
I have a control that is created like so: public partial class MYControl :
I have the following VB.NET class definition: <Serializable()> Partial Public Class Customers End Class
Anyone knows if is possible to have partial class definition on C++ ? Something
I have been using the partial class modifier for some time in order to
I have dbml with single table users i want add partial class for User
I have a partial that renders a select box using the following method: <%=
I have this partial code: if ($getRecords = $con->prepare(SELECT * FROM AUCTIONS WHERE ARTICLE_NO
I'm wondering why the 'partial class' concept even exists in C#/VB.NET. I'm working on
I hope this makes sense. I have a ASP.NET web application that uses Entity

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.