Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Tue, 26 Aug 2008 04:48:01 -0700,    group: microsoft.public.dotnet.framework.windowsforms.databinding        back       


Inherited interface and Bindinglist   
Hi All,
I am using a generic Bindinglist .
The class type of the objects in the generic list is derived from a base 
class.
This baseclass implements three properties of the base interface.
The derived class implements two more properties from the derived interface 
which inherits from the base interface.

These objects are added to a generic list.
This list is fed to a generic binding list.
This generic bindinglist is set as the datasource for a datagridview control.

The propblem is that the datagridview only displays the properties from the 
derived interface and not the properties from the base interface. Is this a 
bug or how can i fix this.


   public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            List<IDerivedInterface> lst = new List<IDerivedInterface>();
            for (int i = 0; i < 20; i++) {
                lst.Add(new DerivedClass());
            }
            BindingList<IDerivedInterface> dataSource = new    
BindingList<IDerivedInterface>(lst);
            dataGridView1.DataSource = dataSource;
        }
    }
    public interface IBaseInterface
    {
        string PropertyNameA { get;set;}
        string PropertyNameB { get;set;}
        string PropertyNameC { get;set;}

    }
    public interface IDerivedInterface 
    {
        string PropertyNameD { get;set;}
        string PropertyNameE { get;set;}
    }
    public class BaseClass : IBaseInterface
    {

        public BaseClass()
        {

        }

        #region IBaseInterface Members

        public string PropertyNameA
        {
            get { return "PropertyNameA"; }
            set { ;; }
        }

        public string PropertyNameB
        {
            get { return "PropertyNameB"; }
            set { ;; }
        }

        public string PropertyNameC
        {
            get { return "PropertyNameC"; }
            set { ;; }
        }

        #endregion
    }
    public class DerivedClass : BaseClass, IDerivedInterface
    {

        public DerivedClass()
        {

        }

        #region IDerivedInterface Members

        public string PropertyNameD
        {
            get { return "PropertyNameD"; }
            set { ;; }
        }

        public string PropertyNameE
        {
            get { return "PropertyNameE"; }
            set { ;; }
        }

        #endregion
    }
Best regards,
Hans
date: Tue, 26 Aug 2008 04:48:01 -0700   author:   Hans Bertram Hans

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us