how to sort winform's databinding by related table's column?

I have a windows form bound to a "products" table.

I've tried binding to a dataview and a dataviewmanager, but i can't figure out how to achieve a sort by joined table.

"products" table has a column "seasonName".  this links to a "seasons" table.  "seasons" table has a column called "sortOrder".  I want to sort by that column first.

if I were to do it in SQL it would look like:

SELECT products.* FROM products JOIN seasons ON seasons.Name = products.seasonName ORDER BY seasons.sortOrder, products.Category, products.Name


does anybody know how to achieve this functionality in a winform binding aspect 

thanks 


Answer this question

how to sort winform's databinding by related table's column?

  • Salvo Dan

    try
    MyDataTable.DataView.Sort = "sortOrder, Category, Name";


  • Orcun Baslak

    sorry, i guess i should clarify, this winform is NOT using a datagrid.
    just textboxes & such bound to that "products" table.

  • bzurer

    To do this I had to an expression column (that used the relation to lookup the sortOrder field) to the DataTable.

    -Michael

  • williamguy

    Michael:

    can you tell me how one creates an expression column

    i guess i should ask, did you create this expression column in your database or in your .Net dataset 

    i'll go dig around in the docs...  i have never done this before (in a DataSet I mean).  


    Thanks  :)

  • Hammy20111

    good idea...


    tried it, didn't work.  exception was "Couldn't find column 'seasons.sortOrder'.

    I also tried a Sort = "Relation9.sortOrder"  (Relation9 being the name of the relation in the dataset joining the two tables).  same error there.   :(

  • Jerry Povse - MSFT

    I would have thought
    MyDataTable.DataView.Sort = "seasons.sortOrder, products.Category, products.Name"
    would have worked but you would need to bind the controls to the DataView, not the Table.

  • how to sort winform's databinding by related table's column?