DataGrid: Help accessing a control defined in a CellEditingTemplate

Apr 10, 2009 at 10:31 PM

I am using the WPF DataGrid with a DataGridTemplateColumn.  The DataGridTemplateColumn.CellEditingTemplate contains a ComboBox with IsEditable set to 'true'.  In my RowEditEnding event handler, I'd like to read the Text property of that ComboBox - the only problem is that I don't know how to retrieve the ComboBox instance within the event handler in order to get to the Text property.

For reference, here's my DataTemplate:
                <!--  ... -->
                        <ComboBox IsEditable="True" ItemsSource="{Binding Source={StaticResource ProductCategories}}" SelectedItem="{Binding Path=Name}" DisplayMemberPath="Name" />
                <!--  ... -->

And my code:
         private void productsDataGrid_RowEditEnding(object sender, DataGridRowEditEndingEventArgs e)
            // UH-OH! Where do I find the ComboBox instance?

I know that I can get to the current affected row using e.Row... Maybe the solution involves something using e.Row?
I've tried walking the visual tree recursively from e.Row down looking for an instance of ComboBox, but no dice.  I'm almost positive that the solution is simple, however, I'm relativley new to WPF in general.
Any suggestions would be much appreciated.


Charles Strahan
Apr 14, 2009 at 8:26 AM
Assuming that you are using data binding, DataGridRowEditEndingEventArgs.Row.Item should help.