The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Bindingsource datamember?

Last post 08-25-2008, 5:52 AM by rotep. 2 replies.
Sort Posts: Previous Next
  •  08-25-2008, 12:51 AM 10894

    Bindingsource datamember?

    Hi,

    I'm trying to use a generated collection as a datasource for a BindingSource. In code everything works fine like so:

    Code:
    1    theList = New BLL.EpPlanCollection
    2    theList.LoadAll()
    3    
    4    Dim bs As New BindingSource
    5    bs.DataSource = theList
    6    
    7    DataGridView1.DataSource = bs
    
     

    If I try to add a BindingSource in designtime there is a problem. I can choose the EpPlanCollection as a datasource for the BindingSource, but I cannot choose the right DataMember or invoke the LoadAll function... I can only choose related collections as a DataMember, but I need the collection itself like in the code example... I've tried adding the following code to my custom EpPlan class, but the property doesn't show up...

    Code:
    #Region "EpPlanCollection - Zero To Many"
            ''' <summary>
            ''' All Ep Plans
            ''' </summary>
    
            <XmlIgnore()> _
            Public Property EpPlanCollection() As EpPlanCollection
                Get
                    If Me._EpPlanCollection Is Nothing Then
                        Me._EpPlanCollection = New EpPlanCollection()
                        Me._EpPlanCollection.es.Connection.Name = Me.es.Connection.Name
                        Me.SetPostSave("EpPlanCollection", Me._EpPlanCollection)
    
                        Me._EpPlanCollection.LoadAll()
                    End If
    
                    Return Me._EpPlanCollection
                End Get
    
                Set(ByVal value As EpPlanCollection)
                    If Not value Is Nothing Then Throw New Exception("'value' Must be null")
    
                    If Not Me._EpPlanCollection Is Nothing Then
                        Me.RemovePostSave("EpPlanCollection")
                        Me._EpPlanCollection = Nothing
                    End If
                End Set
    
            End Property
    
            Private _EpPlanCollection As EpPlanCollection
    #End Region
    
     

    Can anybody assist please?

  •  08-25-2008, 4:05 AM 10895 in reply to 10894

    Re: Bindingsource datamember?

    Open the EntitySpacesDemo in VS, and take a look at SimpleGrid.cs in Design View. An EmployeesCollection, BindingSource, and DataGridView have been dragged to the Form from the ToolBox. The bindingSource1.DataSource is set to employeesCollection. The dataGridView1.DataSource is set to bindingSource1. No DataMember is set for either.

    By default, AutoGenerateColumns is true for the DataGridView, and you would normally see all Employees columns in the Designer. If you scroll down the DataGridView's Properties, and open the Columns Collection, you will see that a number of columns have been removed, and the EmployeeID column is set to ReadOnly. Once changes are made to the Columns Collection in the Designer, AutoGenerateColumns is automatically set to false, and only the selected columns will display. You could, also, override the HeaderText for each column to display something other than the default property name.

    At runtime, you need to instantiate the collection, load it, and bind it. You will find code almost identical to your first code block in the Form Load event in Code View for SimpleGrid.cs.

    Are you trying to view data at design time?


    David Neal Parsons
    www.entityspaces.net
  •  08-25-2008, 5:52 AM 10899 in reply to 10895

    Re: Bindingsource datamember?

    I'm trying to set the DataMember at DesignTime, probably to see the data at design time (noobical, not cynical)...

    I guess instantiating and loading the collection at runtime wouldn't be a problem, this should be done in the Form_Load event i presume? (sorry don't have the demo installed, no admin rights..)

View as RSS news feed in XML