I have a xamDataGrid bound to an ObservableCollection<Note>. Among other things the Note objects have properties for NoteTypeID and NoteSubTypeID.
I also have a ReadOnlyCollection<NoteType>. Each NoteType object exposes its ID and Name as well as a ReadOnlyCollection<NoteSubType>. Each NoteType object has a unique list of NoteSubTypes (but the NoteSubTypeID's aren't unique).
I've bound the NoteTypeID to a XamComboEditor and that column is displaying correctly. What I'm having trouble with is binding the second XamComboEditor. I need to set the ItemsSource property to the NoteType XamComboEditor's SelectedItem.SubTypes.
I have this working outside of the grid, but can't seem to get it working within the grid. Hints?
Is this even possible? Or is the grid going to try to use the same ItemsSource for the combobox in each row?
Hello,
If it is working outside the XamDataGrid, you should be able to make it run inside as well. I am a little lost with Note, NoteType, NoteTypeID and NoteSubType, but if you provide us with a sample of your structure and what you are trying to achieve, then we can definitely take a look at it.
Thanks!
I've noticed one more issue with this setup. When I drag the NoteType into the Group Area the grouping works as I'd expect, but if instead I drag the NoteSubType it displays the NoteSubType.ID instead of the NoteSubType.Name.
What's really weird is that if I drag the NoteType, then drag the NoteSubType both columns groups dislpay their ID's instead of their Names.
I would expect these to always display the value that I selected in the DisplayMemberPath.
Thanks. It was surprisingly easy once you pointed the way.
I've attached the sample project again so if anyone with the same issue come across this thread they'll have a complete sample to work from.
I am sorry, this thread must have slipped from me. Thank you for providing the project and bumping this up.
The reason why this does not work in the XamDataGrid is because you are using ElementName in the Binding expressions that are in styles. This will have no effect when you bind inside a style's setter. You can only use the DataContext or RelativeSource markup. Another issue is the data structure. You are trying to get the selected item of the first XamComboEditor, but you would not have direct access to it from other cells. You have to the cell's value, but that would not work, because it is of type NoteTypeId and you need its sub types. Your best option here is to use an IValueConverter for the second XamComboEditor ( NoteSubTypeID ) cell.
<Style TargetType="{x:Type e:XamComboEditor}">
<Setter Property="ItemsSource" Value="{Binding Path=Cells[NoteTypeID].Value}" />
....
</Style>
This is the correct syntax to bind to the value of the NoteTypeID cell, respectively the selected item of its XamComboEditor. However, in the binding expression you would have to add a converter which will take the NoteTypeID and return the corresponding object's SubTypes
<Setter Property="ItemsSource" Value="{Binding Path=Cells[NoteTypeID].Value, Converter={StaticResource myConverter}}" />
I hate to be a nag, but it's been two weeks. Is there any update?
I attached a sample project I put together this morning showing how we're using Notes, NoteTypes and NoteSubTypes.
The key is that the NoteSubType list pulls from a different SQL table for each NoteType, so we have overlap on the NoteSubType.ID, so we can't use a master list of SubTypes (not my design, I'm just working with it...)