How to sort a DataGrid bound to a DataRelation?

From: Kevin P. Fleming (kpfleming_at_backtobasicsmgmt.com)
Date: 05/05/04


Date: Wed, 05 May 2004 07:21:57 -0700

I've got a strongly typed DataSet containing two tables with a
DataRelation defining the parent-child relationship between them. On my
form, there is a DropDownList ComboBox bound to the parent table,
allowing the user to select a row from that table.

Also I have a DataGrid bound to the DataRelation between the parent and
child tables (DataSource is set to the DataSet, DataMember is set to the
relation name). This works fine, as the user can use the ComboBox to
select a parent table row and the DataGrid properly displays the related
rows from the child table.

However, I cannot seem to find a way get the DataGrid to automatically
sort the child rows by their Name column. I can't use a DataView because
DataViews can't be bound to DataRelations. I have set the
DefaultView.Sort property of the child table, but that has no effect,
presumably because the DataGrid's internal DataView is not being built
directly from the child table, but from the DataRelation. I _can_
manually sort the rows in the grid, of course, but this is not very
elegant :-)

I even tried using the CurrencyManager returned from getting the
DataGrid's BindingContext, but the .List property for that
CurrencyManager is not a DataView, it's a DataViewManager, which doesn't
have a .Sort property.

Anyone have any ideas?



Relevant Pages

  • Re: GetParentRow(s) or GetChildRows?
    ... Orders & Order Details. ... Which table would you expect to be the Parent? ... Which table would you expect to be the Child? ... > Creates a DataRelation with a specified parent and child column, ...
    (microsoft.public.dotnet.general)
  • Re: GetParentRow(s) or GetChildRows?
    ... Thanks for your reply, Jay. ... Creates a DataRelation with a specified parent and child column, ...
    (microsoft.public.dotnet.general)
  • Re: DataRelations and DataGrids
    ... Create a DataRelation LookupToMain. ... > a DataRelation between your parent tables and child tables and then use ... > relationships may return multiple rows, you must include the reference ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: getting data from two datatables
    ... Set the Current as the parent table and set the former as the child. ... Use the RowFilter of the DataView ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: DataRelations and DataGrids
    ... Yes you can use a DataRelation for this purpose, ... A parent table may be referenced in an expression by prepending the ... A column in a child table may be referenced in an expression by ... you must include the reference ...
    (microsoft.public.dotnet.framework.windowsforms)

Loading