Re: How to sort a DataGrid bound to a DataRelation?
From: Josh (joshualangemann_at_gmail.com)
Date: 12/09/04
- Next message: Josh: "Re: How to sort a DataGrid bound to a DataRelation?"
- Previous message: Serge Shimanovsky: "Bind CheckedListBox to ArrayList of objects"
- Next in thread: Josh: "Re: How to sort a DataGrid bound to a DataRelation?"
- Maybe reply: Josh: "Re: How to sort a DataGrid bound to a DataRelation?"
- Messages sorted by: [ date ] [ thread ]
Date: 8 Dec 2004 20:56:56 -0800
I just had a similar problem, where I was attempting to sort the
contents of a combobox that was bound to a datarelation. Eventually I
found that I could indeed retrieve the DataView from the currency
manager and set the sort on it. However, it appears that the DataView
is re-created whenever the position of the parent bindingmanager
changes, requiring the sort to be re-done repeatedly. Here is what I
ended up implementing successfully. Note that Payment is my parent
table, and PaymentAudit is the child table. PaymentAudit records need
to be appear reverse sorted in the combobox:
// In the load event of the form, bind to the CurrentChanged and
PositionChanged events of the parent datatable, Payment:
this.BindingContext[this.paymentListData, "Payment"].CurrentChanged +=
new EventHandler(PaymentListTabs_PaymentChanged);
this.BindingContext[this.paymentListData, "Payment"].PositionChanged +=
new EventHandler(PaymentListTabs_PaymentChanged);
// Event handler that will run with the Payment Position or Current
item changes
private void PaymentListTabs_PaymentChanged(object sender, EventArgs e)
{
// Sort the Payment Audit records if there are any
if (this.BindingContext[this.paymentListData,
"Payment.PaymentPaymentAudit"].Count > 0)
((DataRowView)this.BindingContext[this.paymentListData,
"Payment.PaymentPaymentAudit"].Current).DataView.Sort = "PaymentAuditId
DESC";
}
Hopefully you can interpret the code despite the text wrapping!
Thanks,
Josh
Kevin P. Fleming wrote:
> 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?
- Next message: Josh: "Re: How to sort a DataGrid bound to a DataRelation?"
- Previous message: Serge Shimanovsky: "Bind CheckedListBox to ArrayList of objects"
- Next in thread: Josh: "Re: How to sort a DataGrid bound to a DataRelation?"
- Maybe reply: Josh: "Re: How to sort a DataGrid bound to a DataRelation?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|