This is a migrated thread and some comments may be shown as answers.

Generic List and Objects

2 Answers 338 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Josh Fruits
Top achievements
Rank 1
Josh Fruits asked on 17 Aug 2009, 10:21 PM
Hello,

I'm using the trial version and trying to find out if Telerik Reporting is right for me. For the most part it's seemed like an excellent choice, but I do have one issue that I haven't been able to figure out.

For the most part, my binding will be to business objects. One item that often comes up in my business objects is a generic list of IP Addresses (System.Net.IPAddress). When I try to do this, I get a red box on my report that says

"An error has occured while processing TextBox 'TextBox1':
The expression contains object 'Item' that is not defined in the current context.

Textbox1 is within the details section, and the details section is the only section on the report.

To test this, I created a class called Addresses in 3 different ways, and used this code in my report's constructor:
    Public Sub New()  
        InitializeComponent()  
 
        Me.DataSource = New Addresses()  
        Me.TextBox1.Value = "=Fields.Item" 
 
    End Sub 

Then I tried 3 different versions of the Addresses() class.

Version 1:
Public Class Addresses  
    Inherits List(Of System.Net.IPAddress)  
 
    Public Sub New()  
        Me.Add(System.Net.IPAddress.Parse("192.168.0.1"))  
        Me.Add(System.Net.IPAddress.Parse("192.168.0.2"))  
        Me.Add(System.Net.IPAddress.Parse("192.168.0.3"))  
        Me.Add(System.Net.IPAddress.Parse("192.168.0.4"))  
        Me.Add(System.Net.IPAddress.Parse("192.168.0.5"))  
 
    End Sub 
 
End Class 
This produced the error above.

Version 2:
Public Class Addresses  
    Inherits List(Of String)  
 
    Public Sub New()  
        Me.Add("192.168.0.1")  
        Me.Add("192.168.0.2")  
        Me.Add("192.168.0.3")  
        Me.Add("192.168.0.4")  
        Me.Add("192.168.0.5")  
 
    End Sub 
 
End Class 
I tried the list as a string, just because that's how all the samples I saw on the site are. This produced the expected results of a nicely formatted list of IP Addresses. However, my business objects do not have the IP Addresses as Strings, they are System.Net.IPAddress objects. I just tried this one for proof of concept.

Version 3:
Public Class Addresses  
 
    Private _item As System.Net.IPAddress = System.Net.IPAddress.Parse("192.168.0.2")  
    Public Property Item() As System.Net.IPAddress  
        Get 
            Return Me._item  
        End Get 
        Set(ByVal value As System.Net.IPAddress)  
            Me._item = value  
        End Set 
    End Property 
End Class 
I tried this to to see if an IP Address as a property would render properly on the report, and it did.

With all 3 versions, I left the constructor the same way, and the textbox in the details section. It seems that as a standard property, the System.Net.IPAddress object could be rendered properly, and it also seemed that Telerik Reporting can understand a generic list, however, when I combine the two, it does not seem that Telerik Reporting can understand a Generic List of System.Net.IPAddress objects. Is this correct, or is there another method I am missing?

As an aside, if you are not familiar with System.Net.IPAddress, the familiar format of an IP address (ex. 192.168.0.1) is returned with the .ToString() method. It does not have a property to return it.

Thanks for any help you can give.

Josh

2 Answers, 1 is accepted

Sort by
0
Accepted
Milen | Product Manager @DX
Telerik team
answered on 18 Aug 2009, 02:10 PM
Hi Josh Fruits,

I am happy to find out that you like our product.

The Item property is available in the expression context only when the datasource is a list of simple objects (like string, int, etc.)
When the list consists of complex objects, you can directly access the public properties of the current item in the list. For example if you have list of addresses as a datasource, expressions would look like
= Fields.City
= Fields.Country
etc.

However you cannot access methods of that object this way. So in your scenario a user function can do the job:

Expression:
     = MyUserFunction(ReportItem)
Function implementation:
    Public Shared Function MyUserFunction(ByVal ri As Processing.ReportItem) As String
        Return ri.DataObject.RawData.ToString()
    End Function


Write us if you need further assistance.

Kind regards,
Milen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Josh Fruits
Top achievements
Rank 1
answered on 18 Aug 2009, 02:34 PM
Works great! Simple and reusable!

Thanks

Josh
Tags
General Discussions
Asked by
Josh Fruits
Top achievements
Rank 1
Answers by
Milen | Product Manager @DX
Telerik team
Josh Fruits
Top achievements
Rank 1
Share this question
or