Binding the DXGrid to an XPO Datasource

I found a forum post today about binding an XPO datasource to the DevExpress DXGrid control. I had posted about this on my DX blog before, but that is more than a year ago – things are moving along quickly, and this post is very likely going to be outdated again with 2010.1… but that’s life, isn’t it 😃

So, I thought I should have another look and see what changed and what might be easier. So I started recreating the steps I went through for that other post, with the same data and all, but with the current (2009.3) version of the libraries. I’ll document the differences I found below, but include all the steps I took for completeness’ sake – there’ll be a bit of replication, but it’s still worth reading the old post anyway! The first difference that came up is that the GridColumnView is now called TableView. Okay, that’s easy. With that change, the first grid worked with the same XAML as before: This is based on the idea that a data source is assigned in the code-behind, which I’m (still) doing like this:

UnitOfWork uow;

protected override void OnInitialized(EventArgs e) {

  uow = new UnitOfWork();
  customerGrid.DataSource = new XPCollection(uow);

My next step was to try and get the master/detail setup working. Previously this was a bit weird, with the need to extract the DataContext from the current row etc etc. I plugged in my old binding:

DataSource="{Binding ElementName=customerGrid, Path=View.CurrentRowData.DataContext.This.Orders}"

And… nothing. Hm. A bit more looking around, and it turns out this has simply become much easier. My binding now changes to this and everything works:

DataSource="{Binding ElementName=customerGrid,

This is very nice! Not only is it much easier to retrieve the information about the currently selected object, there’s also no problem anymore with intermediate data types with copied properties that aren’t all there… cool. Moving on, I want to activate XPO Server mode. The basics of this haven’t changed, so I still need to set my datasource to an instance of XPServerCollectionSource:

customerGrid.DataSource =
  new XPServerCollectionSource(uow, typeof(Customer));

The problem with the “detail” data remains though, and some details have changed for the method of hooking up through the event. The event that fires when the focused row changes is now called FocusedRowChanged, so my XAML now looks like this: On the other hand, the code behind is now simpler as well, due to the same changes as above:

private void TableView_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) {
  var selectedCustomer = customerGrid.View.FocusedRow as Customer;
  if (selectedCustomer != null)
    orderGrid.DataSource = new XPServerCollectionSource(uow, typeof(Order),
      new BinaryOperator("Customer", selectedCustomer));

So far, so good. I didn’t go through the steps of automating the collection encapsulation again – they are outlined in the original post and the only differences that will be relevant to that code are those already described above. Overall – some changes, but they are the good kind because they make things simpler. Good work, DX! Here’s the new version of my demo application, built against DXperience 9.3.3:

Have fun!

Sorry, this blog does not support comments.

I used various blog hosting services since this blog was established in 2005, but unfortunately they turned out to be unreliable in the long term and comment threads were lost in unavoidable transitions. At this time I don't want to enable third-party services for comments since it has become obvious in recent years that these providers invariably monetize information about their visitors and users.

Please use the links in the page footer to get in touch with me. I'm available for conversations on Keybase, Matrix, Mastodon or Twitter, as well as via email.