Results 1 to 5 of 5

Thread: [2010] What is wrong with the code?

  1. #1

    Thread Starter
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    Angry [2010] What is wrong with the code?

    Hi, Here I gave the code. My aim : I am trying to make the frmView to generic for populating from Manager Class List.


    Code:
    namespace WindowsFormsApplication1
    {
        public abstract class AbsLookUpView 
        {
            public abstract string LookupName{get;}
        }
    }
    
    
    --------------------------------------------------------------------------
    
    namespace WindowsFormsApplication1
    {
        public abstract class AbsManager<T> where T:AbsLookUpView
        {
          public abstract List<T> LoadAll();
    
        }
    }
    
    ==========================================================
    
    public partial class Department: AbsLookUpView
        {
            public override string LookupName
            {
                get
                {
                    return "Department";
                }
            }
        }
    
    ==========================================================
    
    
    namespace WindowsFormsApplication1
    {
        public class DeptManager : AbsManager<Department>
        {
            private DataClasses1DataContext dc = new DataClasses1DataContext();
    
    
            public override List<Department> LoadAll()
            {
                return dc.Departments.ToList<Department>();
            }
        }
    }
    
    
    ==========================================================
    
    namespace WindowsFormsApplication1
    {
        public partial class frmView : Form
        {
            public AbsManager<AbsLookUpView> ManagerCls;
    
    
            public void BindGrid()
            {
                this.lkpDataGridView.DataSource = ManagerCls.LoadAll();
            }
    
        }
    }
    
    ==========================================================
    
    namespace WindowsFormsApplication1
    {
        public partial class frmTest : frmView
        {
            public frmTest()
            {
                InitializeComponent();
            }
    
    
    
            private void frmTest_Load(object sender, EventArgs e)
            {
    
                AbsManager<AbsLookUpView> dmb ;
    
                DeptManager dm = new DeptManager();
                dmb = dm; [Error in this line is given below]
                this.ManagerCls = dmb;
                this.BindGrid();
                
                Form5 f = new Form5(this);
                this.ChildForm = f;
    
            }
        }
    }
    ==========================================================
    Error: Cannot implicitly convert type 'WindowsFormsApplication1.DeptManager' to 'WindowsFormsApplication1.AbsManager<WindowsFormsApplication1.AbsLookUpView>' E:\test\WindowsFormsApplication1\WindowsFormsApplication1\frmTest.cs


    here, DeptManager is inherited from AbsManager<WindowsFormsApplication1.AbsLookUpView>. Then why it throws error. Pls explain.

    What is wrong with the above code. Why is this error is occuring? Pls explain experts.
    God has been pleased to place as a king or cobbler do the work sincerely

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2010] What is wrong with the code?

    "DeptManager is inherited from AbsManager<WindowsFormsApplication1.AbsLookUpView>"
    It is?
    You have: public class DeptManager : AbsManager<Department>
    If it inherited from AbsLookUpView wouldn't it look like this:
    public class DeptManager : AbsManager<AbsLookUpView>

    Or did I miss something?


    -tg

    Edit - never mind... I did miss something... ok... back to square 1.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2010] What is wrong with the code?

    The fact that String inherits Object does not mean that List<String> inherits List<Object>. Likewise, the fact that Department inherits AbsLookUpView does not mean that AbsManager<Department> inherits AbsManager<AbsLookUpView>. Your DeptManager class inherits AbsManager<Department> so it can be cast as type AbsManager<Department>. It doesn't inherit AbsManager<AbsLookUpView> so it can't be cast as that type.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Addicted Member senthilkumartd's Avatar
    Join Date
    Feb 2005
    Posts
    206

    Re: [2010] What is wrong with the code?

    Then, how can we change this code to achieve the aim. Any suggestion to achieve this
    God has been pleased to place as a king or cobbler do the work sincerely

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2010] What is wrong with the code?

    Quote Originally Posted by senthilkumartd View Post
    Then, how can we change this code to achieve the aim. Any suggestion to achieve this
    You have to change your aim.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width