none
Walkthrough DataGridView Master Detail Not Working RRS feed

Answers

  • Hi markev;

    Just one small but important mis translation in your code. The original had the following

    public class ObservableListSource<T> : ObservableCollection<T>, IListSource where T : class

    This places a constraints on the T to be of type class.

    In Visual Basic it needs to be as follows :

    Public Class ClassName(Of T As Constraints)

    So in you project you need to make the change to the ObservableListSource class as follows.

    Imports System.ComponentModel
    Imports System.Collections.ObjectModel
    Imports System.Data.Entity
    
    Public Class ObservableListSource(Of T As Class)
        Inherits ObservableCollection(Of T)
        Implements IListSource
    
        Private _bindingList As IBindingList
    
        Public ReadOnly Property ContainsListCollection() As Boolean Implements IListSource.ContainsListCollection
            Get
                Return False
            End Get
        End Property
    
        Public Function GetList() As IList Implements IListSource.GetList
    
            Return IIf(_bindingList IsNot Nothing, _bindingList, Me.ToBindingList())
    
        End Function
    
    End Class


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by markev Sunday, February 12, 2012 7:35 AM
    Saturday, February 11, 2012 9:47 PM

All replies

  • Hi Mark;

    The only exception that was thrown while I was testing was the following:

    "The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value. The statement has been terminated."

    This will happen when attempting to modify a date time field in the database with a DateTime data type in the program. This is due to the fact that SQL server datetime data type gets saved with a different perssion then what the CLR DateTime date has. To get around this issue configure the StartDate in the Department class to create that field in the database as a datetime2, that can be done as follows:

    ' Modify the SchoolEntities class as by adding the following Sub.

        Protected Overrides Sub OnModelCreating(ByVal modelBuilder As DbModelBuilder)
            modelBuilder.Entity(Of Department)().Property(Function(sd) sd.StartDate).HasColumnType("datetime2")
        End Sub

    If you have come accross some other exception then please post here the full message here.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Saturday, February 11, 2012 5:13 PM
  • Hi

    I did see that error, but thought it was only when I didn't fill in the date field.

    The problem I had was that if I add a new row to the courses detail grid it isn't saved, and if I delete a row from the courses detail grid it isn't deleted. It didn't seem to throw an error. Changes to existing rows are saved OK.

    Mark

    Saturday, February 11, 2012 5:55 PM
  • Hi markev;

    Just one small but important mis translation in your code. The original had the following

    public class ObservableListSource<T> : ObservableCollection<T>, IListSource where T : class

    This places a constraints on the T to be of type class.

    In Visual Basic it needs to be as follows :

    Public Class ClassName(Of T As Constraints)

    So in you project you need to make the change to the ObservableListSource class as follows.

    Imports System.ComponentModel
    Imports System.Collections.ObjectModel
    Imports System.Data.Entity
    
    Public Class ObservableListSource(Of T As Class)
        Inherits ObservableCollection(Of T)
        Implements IListSource
    
        Private _bindingList As IBindingList
    
        Public ReadOnly Property ContainsListCollection() As Boolean Implements IListSource.ContainsListCollection
            Get
                Return False
            End Get
        End Property
    
        Public Function GetList() As IList Implements IListSource.GetList
    
            Return IIf(_bindingList IsNot Nothing, _bindingList, Me.ToBindingList())
    
        End Function
    
    End Class


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    • Marked as answer by markev Sunday, February 12, 2012 7:35 AM
    Saturday, February 11, 2012 9:47 PM
  • Thanks very much - my understanding of C syntax not so hot!

    Mark

    Sunday, February 12, 2012 7:36 AM
  • Not a problem Mark, glad I was able to help.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    Sunday, February 12, 2012 1:55 PM