Home > VB.NET > Retrieve Class Properties

Retrieve Class Properties

Get all of the Properties for a Class call Invoices

   Private Function GetInvoiceProperties() as Boolean
         ' List the properties.
         Dim property_value As Object
         Dim properties_info As PropertyInfo() = Invoices(0).[GetType]().GetProperties()

         lvwProperties.BeginUpdate()
         lvwProperties.Items.Clear()
         For i As Integer = 0 To properties_info.Length - 1
            With properties_info(i)
               If .GetIndexParameters().Length = 0 Then
                  property_value = .GetValue(Invoices(RecordNumber - 1), Nothing)
                  If property_value Is Nothing Then
                     ListViewMakeRow(lvwProperties, .Name, "<Nothing>")
                  Else
                     ListViewMakeRow(lvwProperties, .Name, property_value.ToString)
                  End If
               Else
                  ListViewMakeRow(lvwProperties, .Name, "<array>")
               End If
            End With
         Next i
   End Function

   Private Sub ListViewMakeRow(ByVal lvw As ListView, ByVal item_title As String, ByVal ParamArray subitem_titles() As String)
      Try
         ' Make the item.
         Dim new_item As ListViewItem = lvw.Items.Add(item_title)

         ' Make the sub-items.
         For i As Integer = subitem_titles.GetLowerBound(0) To subitem_titles.GetUpperBound(0)
            new_item.SubItems.Add(subitem_titles(i))
         Next i
      Catch ex As Exception

      End Try
   End Sub
Advertisements
Categories: VB.NET Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: