none
Binding select columns of related entity to grid RRS feed

  • Question

  • Hi

    I have two 1-N related entities which need to be bound to two master/child DataGridViews. I am retrieving data via below LINQ;

    Dim dataSource = Context.MyEntity.Include("MyRelatedEntity").Select(Function(a) New With { _
        .A = a.A, _
        .B = a.C, _
        .C = a.MyRelatedEntity.Select(Function(n) n.C), _
        .D = a.MyRelatedEntity.Select(Function(n) n.D) _
       })
    

    I am binding main entity (fields A & B) to master DataGridView as below;

    MyEntityBindingSource.DataSource = dataSource
    

    I have also set child DataGridView datasource as below;

    MyRelatedEntityBindingSource.DataSource = MyEntityBindingSource
    

    However I am stuck on how to set data member property of child DataGridView in this scenario so the grid displays the child entity (fields C & D) values.
     

    MyRelatedEntityBindingSource.DataMember = ???
    

    Any help to resolve this would be appreciated.

    Many Thanks

    Regards

    Sunday, August 21, 2011 12:25 AM

Answers

  • Hi,

    Welcome!

    It's hard to do this in this way, My suggestion is: use ObjectDataSource to handle the related entities.

    You can use SelectChanged Event to set the related DataGridView's datasource, this is the old way.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by Y a h y a Thursday, September 1, 2011 7:32 AM
    Tuesday, August 23, 2011 6:24 AM
    Moderator

All replies

  • Hi,

    Welcome!

    It's hard to do this in this way, My suggestion is: use ObjectDataSource to handle the related entities.

    You can use SelectChanged Event to set the related DataGridView's datasource, this is the old way.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    • Marked as answer by Y a h y a Thursday, September 1, 2011 7:32 AM
    Tuesday, August 23, 2011 6:24 AM
    Moderator
  • Hi, 

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions?

    If you need further assistance, please feel free to let me know.   I will be more than happy to be of assistance.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, August 26, 2011 3:22 AM
    Moderator
  • Hi Alan

    Many thanks. I'll test the suggested method and will come back in a day or so.

    Thanks again.

    Regards

    Friday, August 26, 2011 4:53 AM
  • Hi Yahya,

    Any updates for your problem.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 1, 2011 6:31 AM
    Moderator