DataGrid - Columns from 2 sources

Feb 27, 2009 at 10:15 AM

Here is my problem. I have a DataGrid with ItemSource. It works fine. This ItemSource is a list of elements. I added another column of type DataGridCheckBoxColumn and I'd like to bind it to an object, different from my ItemSource. How to do that ?


I tried to browse rows but I don't know how to do that.
Thanks for answers

Feb 27, 2009 at 1:41 PM
How your checkbox is related to other data in row?
Feb 27, 2009 at 1:52 PM
Well, I can maybe describe more my application.
I put Visual on a Canvas. Theses visuals have fields based on a class and this class contains a List, ProductsLinks.
In my DataGrid, I have a lot of informations like PRODUCT_ID, PRODUCT_NAME... All theses informations are displayed for all my Visuals but the DataGridCheckBoxColumn should be binded to ProductsLinks (a list of PRODUCT_ID).
So when I select a Visual, let's call it MyVisual, I check some products, store this in ProductLinks..., select another Visual, check other products... And finally, I'd like to retrieve the checked products when I select again MyVisual.
Hope it's clear

Mar 2, 2009 at 6:24 PM
The way I see your problem is.....

  1. You have visuals on a canvas whose properties are bound to a class say "MyDataObject".
  2. You have a DataGrid, whose most of the columns are bound to the visuals.
  3. You have one column, the data for which is not available on the Visual.

Following are my suggestions...

  1. Let every thing be bound to data. Meaning your visuals are bound to MyDataObject and let DataGrid also bound to a collection of MyDataObject. This way you dont have to worry about having gettting from two DataSources.
  2. If this is not a possibility and if all of the visuals are FrameworkElements, then you can set the DataContext of your visual to MyDataObject and use paths like "DataContext.ProductLinks" in your Column's Binding property.
  3. If this doesnt work either, then create an AttachedProperty some where, make sure that the value of this property on the visuals is MyDataObject and use this attached property in your Column's Binding property.

I would strongly suggest option (1), if it works.