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.![]()




Reply With Quote