Solved Option Strict On Issue

Microsoft Visual studio professional 201...
August 21, 2013 at 21:27:18
Specs: Windows 7, 2.4ghz xenon
When I run
ObjectListView1.GetColumn(1).AspectGetter = Function(x As Clients) x.FirstName

with option strict on I get an error:
"Option Strict On does not allow narrowing in implicit type conversions between lambada expression and the 'Delegate Function AspectGetter(rowObject as Oject) as Object'.

I do not know of a way to make it work with Option Strict On. I have tried making the function and referencing it but that didn't seem to work.

message edited by rocky3598

See More: Option Strict On Issue

Report •

August 22, 2013 at 05:48:01
✔ Best Answer
It's looking for a function that takes an Object. You're giving it a function that takes a Clients. (I'm not sure why you're taking a class to represent a single client, and making its name plural, but it's not my code, so I don't care.) The solution is to either take an Object, or don't take anything and let VB decide what it should take. In either case, you should convert it to the desired class before using it.
ObjectListView1.GetColumn(1).AspectGetter = Function(x) DirectCast(x, Clients).FirstName

EDIT: CType -> DirectCast. Because some people are picky about those things.

How To Ask Questions The Smart Way

message edited by Razor2.3

Report •

August 22, 2013 at 06:26:16
You are correct it should not be plural. I made the class for a list of clients and wasn't paying attention. Also I'm not sure why it is made that way but its from a custom list view project that I saw on CodeProject that I'm messing with.

That worked great thank you.

Report •
Related Solutions

Ask Question