The EntitySpaces Community

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

Getting a collection from DataviewGrid SelectedRows

Last post 08-28-2008, 1:46 AM by David.Parsons. 1 replies.
Sort Posts: Previous Next
  •  08-27-2008, 4:58 PM 10982

    Getting a collection from DataviewGrid SelectedRows

    I would suppose this should be pretty easy, but the cast is not working. The collection members are have null values. How should I get the selected items as anEntityspaces collection  
    Code:
    if (kgridParts.DataSource != null)
                {
                    m_selectedParts = new BusinessObjects.PartCollection();
    
                    foreach (DataGridViewRow row in kgridParts.SelectedRows)
                    {
                        BusinessObjects.Part newPart = m_selectedParts.AddNew();
                        newPart = (BusinessObjects.Part)row.DataBoundItem;
                        
                        
                    }
    
                    
                    this.lbPartVendors.DataSource = m_selectedParts;
                    this.lbPartVendors.DisplayMember = "PartName";
                                   
                }

    Richard Young
  •  08-28-2008, 1:46 AM 10994 in reply to 10982

    Re: Getting a collection from DataviewGrid SelectedRows

    I believe the cast is working. I think what is happening is that the AddNew sets the newPart entity's collection to m_selectedParts, but assigning the DataBoundItem is reseting the entity's collection back to the original, so it is no longer part of m_selectedParts. Try this approach:

    Code:
    foreach (DataGridViewRow row in kgridParts.SelectedRows)
    {
        BusinessObjects.Part newPart = new BusinessObjects.Part();
        newPart = (BusinessObjects.Part)row.DataBoundItem;
        m_selectedParts.AttachEntity(newPart);
    }

    David Neal Parsons
    www.entityspaces.net
View as RSS news feed in XML