Casting Collection<>

Stimulsoft Reports.NET discussion
Post Reply
admin@secsol.co.uk
Posts: 70
Joined: Wed Jun 01, 2022 8:26 am

Casting Collection<>

Post by admin@secsol.co.uk »

I have some code in a function like this :

Code: Select all

	System.Collections.ObjectModel.Collection<Cypher1.FormField> FieldList = SelectedForm.FieldList as System.Collections.ObjectModel.Collection<Cypher1.FormField>;

  	foreach(Cypher1.FormField F in FieldList)
  	{
  	...... process data here ....
  	}
The SelectedForm.Field List is a Collection<FormField>

But this throws the error :

The error of compilation
The error of compilation is found in the 'Report' report:
Cannot convert type 'Reports.Report.SelectedFormBusinessObject.FieldListBusinessObject' to 'System.Collections.ObjectModel.Collection<Cypher1.FormField>' via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion

What am I doing wrong?
Lech Kulikowski
Posts: 7587
Joined: Tue Mar 20, 2018 5:34 am

Re: Casting Collection<>

Post by Lech Kulikowski »

Hello,

Please send us a sample project that reproduces the issue for analysis.

Thank you.
admin@secsol.co.uk
Posts: 70
Joined: Wed Jun 01, 2022 8:26 am

Re: Casting Collection<>

Post by admin@secsol.co.uk »

I have attached the report
Attachments
RiskAssesment.mrt
(320.08 KiB) Downloaded 16 times
admin@secsol.co.uk
Posts: 70
Joined: Wed Jun 01, 2022 8:26 am

Re: Casting Collection<>

Post by admin@secsol.co.uk »

I have managed to get this to work.

I had to change this

Code: Select all

System.Collections.ObjectModel.Collection<Cypher1.FormField> FieldList = SelectedForm.FieldList as System.Collections.ObjectModel.Collection<Cypher1.FormField>;
by adding the code .Current to the end of SelectedForm.FieldList like this :

Code: Select all

System.Collections.ObjectModel.Collection<Cypher1.FormField> FieldList = SelectedForm.FieldList.Current as System.Collections.ObjectModel.Collection<Cypher1.FormField>;
Lech Kulikowski
Posts: 7587
Joined: Tue Mar 20, 2018 5:34 am

Re: Casting Collection<>

Post by Lech Kulikowski »

Hello,

Thank you for the information.
Post Reply