943,697 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 3463
  • VB.NET RSS
Nov 26th, 2008
-1

loop through properties?

Expand Post »
I'm not quite sure how to tackle this problem. I have a form that displays the properties of a class. I have events for all the properties so the form gets updated automatically when the properties change. However, upon initializing a class, these events do not get called, and so the form starts out blank. What is the best way to program so that when I have a new class, the form displays the class's properties immediately?

(One idea I had was to loop through the properties and call each event... is there a way to loop through class properties in .NET?)
Last edited by Tekito; Nov 26th, 2008 at 12:55 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Tekito is offline Offline
56 posts
since Jan 2008
Nov 26th, 2008
0

Re: loop through properties?

Sure you can, see the implementation below. This example is a copy/paste code from my project in which I added a class "ValidationInstance" which holds a collection of items which should be checked (or préfilled before the handler IsValid will be raisen).
Dim iPropertyCount As Integer = 0
        For Each PropertyItem As PropertyInfo In yourClass.GetType().GetProperties()
            Select Case iPropertyCount
                Case 1 To 10
                    'add the properties of this class to then validation instance

                    Dim strToAdd As String = String.Empty
                    If Not PropertyItem.GetValue(yourClass, Nothing) = Nothing Then
                        strToAdd = PropertyItem.GetValue(yourClass, Nothing).ToString()
                    End If
                    yourClass.ValidationInstance.ValidateRequired(PropertyItem.Name, _
                                                        strToAdd.ToString)

            End Select

            iPropertyCount += 1
        Next
Last edited by 4advanced; Nov 26th, 2008 at 2:09 pm.
Reputation Points: 33
Solved Threads: 10
Junior Poster in Training
4advanced is offline Offline
67 posts
since Nov 2008
Nov 26th, 2008
0

Re: loop through properties?

Okay, thanks.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Tekito is offline Offline
56 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Trying to speed up GUI response time - Combobox SelectIndexValue event slows down app
Next Thread in VB.NET Forum Timeline: Sending mails in vb.net 1.0





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC