Click here to Skip to main content
15,899,025 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionBinding DataGridView to a Generic List of interfaces Pin
droig19-Nov-08 3:21
droig19-Nov-08 3:21 
Hi all!

I'm populating a DataGridView with generic lists of my interfaces and I got this issue:

I have two interfaces and to concrete implementations of them:

Public Interface IMyBaseClass
    Property Name() As String
End Interface

Public MustInherit Class MyBaseClass
    Implements IMyBaseClass

    Private _name As String
    Public Property Name() As String Implements IMyBaseClass.Name
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
End Class

Public Interface IMyConcreteClass
    Inherits IMyBaseClass
    Property Description() As String
End Interface

Public Class MyConcreteClass
    Inherits MyBaseClass
    Implements IMyConcreteClass

    Private _description As String
    Public Property Description() As String Implements IMyConcreteClass.Description
        Get
            Return _description
        End Get
        Set(ByVal value As String)
            _description = value
        End Set
    End Property

End Class


If I bind my grid with a generic list of IMyConcreteClass, the grid just loads the concrete interface propertys (Description) but doesn't loads the base interface propertys (Name).

Here is an example of what i'm doing:

Public Sub LoadTheGride()
    'load some data ont mylist
    Dim classOne As New MyConcreteClass
    Dim classTwo As New MyConcreteClass
    classOne.Name = "class one"
    classOne.Description = "the class one"

    classTwo.Name = "class two"
    classTwo.Description = "the class two"

    Dim myList As List(Of IMyConcreteClass) = New List(Of IMyConcreteClass)
    myList.Add(classOne)
    myList.Add(classTwo)

    'add respective columns
    Dim someGrid As New DataGridView 'actually the grid is in my form but this is just an example
    Dim column1 As New DataGridViewTextBoxColumn()
    Dim column2 As New DataGridViewTextBoxColumn()

    column1.DataPropertyName = "Name"
    column1.Name = "The name"

    column2.DataPropertyName = "Description"
    column2.Name = "The description"

    someGrid.Columns.Add(column1)
    someGrid.Columns.Add(column2)

    'bind
    Dim bs As New BindingSource()
    someGrid.AutoGenerateColumns = False
    someGrid.DataSource = bs
    bs.DataSource = myList
End Sub


At the end i just got this on the screen:

http://img140.imageshack.us/img140/6060/clipboard01au4.png (screencap)

Some one knows what I'm doing wrong? Frown | :(

modified on Thursday, November 20, 2008 8:30 PM

AnswerRe: Binging DataGridView to a Generic List of interfaces Pin
Jon_Boy19-Nov-08 3:32
Jon_Boy19-Nov-08 3:32 
GeneralRe: Binging DataGridView to a Generic List of interfaces Pin
droig19-Nov-08 3:40
droig19-Nov-08 3:40 
GeneralRe: Binging DataGridView to a Generic List of interfaces Pin
Jon_Boy19-Nov-08 4:14
Jon_Boy19-Nov-08 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.