views:

25

answers:

0

Hi,

I cant seem to bind the datagridview's comboBoxColumn's ItemsSource Property the way I want. My Class hierachy used for this application is like this,

  1. I have a class called "PrescriptionViewModel"
  2. Inside it I have set the userControls (the view) data context to an object of "PrescriptionPresenter".
  3. Inside the "PrescriptionPresenter" I have another property of class "DrugSelectionPresenter" -> the property name is DrugSelectPresenter.
  4. The class "DrugSelectionPresenter" has a collection of strings(List) to which Im trying to bind the combobox.

I understand that I cant directly bind to the list of strings because it searches for a property in the ItemsSource of the datagrid.

I tried using following code but still it doesn't work (I can see the error at output windows says it cant find the source). could you please help me to identify whats going on with this code. thanks

<my:DataGrid ItemsSource="{Binding Path=DrugSelectPresenter.SeletedDrugCollection}"  
             AutoGenerateColumns="False" Height="Auto" MaxHeight="240" Name="dataGrid1" Width="Auto" CanUserDeleteRows="True" >
                                    <my:DataGrid.Columns>
                                       <my:DataGridComboBoxColumn 
                                            Header="DoseForm" 
                                            ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}},Path=DataContext.DrugSelectPresenter.DoseFormList}" 
                                            /> 
                                    </my:DataGrid.Columns>
                                </my:DataGrid>

EDIT:

I'm not sure this is the best approach, but I got passed this error using an object data provider. I used it like this

I've created a static method to return the list of objects I need, and then,

in usercontrol.resources section

<ObjectDataProvider 
        IsAsynchronous="True" 
        ObjectType="{x:Type local:DrugSelectionPresenter}" 
        x:Key="doseFormsListDataProvider" MethodName="GetDoseFormsList" />

and in the code

<my:DataGridComboBoxColumn Header="DoseForm" 

ItemsSource="{Binding Source={StaticResource doseFormsListDataProvider}}" />