1

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

cjroebuck
  • 2,273
  • 4
  • 30
  • 46
  • For what it's worth a WPF ListView supports multiple editable cells on the same row: just use CellTemplate instead of DisplayMemberBinding when setting up the column. – itowlson Dec 11 '09 at 00:06

1 Answers1

0

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

Community
  • 1
  • 1
Aran Mulholland
  • 23,555
  • 29
  • 141
  • 228
  • 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 Dec 11 '09 at 11:43