I don't quite understand why this code works... simple, but I just don't get it.

Posted on 2006-05-04
Last Modified: 2010-04-16
I don't understand why you can cast a CurrencyManager as a DataView.

int rowCount = (currManager as DataView).Count;

I don't see how that works, but it does. I know this is really simple, but looking at the class heirarchy for these objects, it just doesn't make sense to me.
Question by:PoeticAudio
    LVL 6

    Author Comment


    It's the CurrencyManager.List that casts, but I still don't get it.

    int rowCount = (currManager.List as DataView).Count;
    LVL 9

    Expert Comment

    I neither understand why it works for you.

    I get a compile-time error in Visual Studio 2005:
    Cannot convert type 'System.Windows.Forms.CurrencyManager' to 'System.Data.DataView' via a built-in conversion
    LVL 6

    Author Comment

    read my second post
    LVL 12

    Accepted Solution


    From MSDN

    The object returned by the List property can be cast to any type that implements the IList interface. This will be commonly used when you know the type of the underlying list. For example, if you are data-bound to a DataSet, the underlying list is a DataView (which implements IList). Other classes that implement the interface (this is not a complete list) include Array, ArrayList, and CollectionBase.

    DataView implements IList as stated above, therefore the Count property is accessible

    The wonders of Interfaces ;-)

    LVL 6

    Author Comment

    ahh. Okay. Thanks man!

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Suggested Solutions

    Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now