views:

379

answers:

2

Hi,

OK So I have a combo box which selects an administrator from a list of administrators:

<ComboBox x:Name="adminCombo"
          ItemsSource="{Binding AdminsList}"
          DisplayMemberPath="Name"
          SelectedValue="{Binding Administrator}"
          SelectedValuePath="Name"/>

and below this I have a WPF Toolkit DataGrid. Each administrator holds a list of user-defined fields (AvailableUDFs). In the first column of my datagrid I want to have an editable template consisting of another combobox whose items source is the list of fields belonging to the selected administrator. The following markup does not work.

<toolkit:DataGrid 
     AutoGenerateColumns="False"
     ItemsSource="{Binding Path=UserDefinedFields}">
     <toolkit:DataGrid.Columns>
        <toolkit:DataGridTemplateColumn Header="Custom Data">
          <toolkit:DataGridTemplateColumn.CellEditingTemplate>
             <DataTemplate>
                  <ComboBox ItemsSource="{Binding ElementName=adminCombo, 
                    Path=SelectedValue.AvailableUDFs}"
                    SelectedValue="{Binding Field.Type}"
                    DisplayMemberPath="Name"/>
             </DataTemplate>
          </toolkit:DataGridTemplateColumn.CellEditingTemplate>
        </toolkit:DataGridTemplateColumn>
     </toolkit:DataGrid.Columns>
</toolkit:DataGrid>

I have also tried Relative Source - Find Ancestor and searching up the tree to the previous combo box, but to no avail. Oddly enough, putting the same combo box into a ListView's items template works fine, the correct list of items shows up dependent on the selected administrator. The problem with using a WPF ListView is that ultimately I want to have other editable cells on the same row, and a plain ListView is not intended for this purpose.

Can anyone help me out? Thanks Chris

A: 

you can use a datagridcombocolumn, and getting the items source to it is a bit tricky, i answered how to do this here, enjoy.

Aran Mulholland
A: 

Thanks for your answer I tried this but the problem is the combo box within the datagrid cannot find the combo box named 'adminCombo'.

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'ElementName=adminCombo'. BindingExpression:Path=SelectedItem.AvailableFundUDFs; DataItem=null; target element is 'ComboBox' (Name=''); target property is 'ItemsSource' (type 'IEnumerable')

cjroebuck