Custom CellType or Control in Datagrid

Apr 14, 2009 at 8:38 PM
I need to create a cell that would work much like a combobox, but instead of a listbox dropping down, it would show a popup form.  When the user selects a item in the popup form, the text needs to be displayed but the value is persisted as well to the cell, since that is what the cell would be bound to in the database.

I need to do it with a popup because I need to be able to do more than what a combobox does.  I need a full form.

Any suggested on how to persist the selected item back to a cell and storing the text/value would be appreciated.
Apr 14, 2009 at 11:55 PM
Just so you know, you can template ComboBoxItems to be virtually anything you want.  If that can meet your needs then you'll get the rest of the functionality you describe for free from the DataGridComboBoxColumn.
Apr 15, 2009 at 1:11 AM
Thanks for the response.  I did actually create a style for a combobox that does what I need.  I just can't figure out how to apply it to a DataGridComboBoxColumn
Apr 15, 2009 at 2:42 AM
See this post,  In particular, number 4 about the ElementStyle and EditingElementStyle.
Apr 15, 2009 at 3:54 AM
Thanks for pointing that out.  I think I resolved it but I am not sure why.  I had created a resource and if I set it like this, it doesn't work:



="{DynamicResource ComboBoxStyle1}"


But if I put the contents of ComboBoxStyle1 inside the control like this, it does work










TargetType="{x:Type ComboBox}">










Value="{StaticResource ComboBoxFocusVisual}" />


....(Left out all because it is alot of XAML)





So I am not sure why it has to be inline like that.

Apr 15, 2009 at 11:46 AM
The issue you are seeing with the DynamicResource is the issue described in this thread,
Apr 15, 2009 at 4:19 PM
Edited Apr 15, 2009 at 4:50 PM
Very helpful.  I am almost there.  Now, here is the only issue I am having left.  My dropdown is now a Datagrid with two buttons at the bottom.  Cancel and Select.  When I hit Select, I need to assign the selected text/value to the text portion of the combobox and close the dropdown.  Cancel just closes the dropdown.

Any help on how I do that?
Apr 16, 2009 at 12:30 AM
This post,, talks about launching a form to edit a row.  Maybe that can give you some ideas on how to do that with just a cell.
Apr 23, 2009 at 12:56 AM

How do you template the combobox items in a DataGridComboBoxColumn?  In guess I didn't think about that when you first responded.  I dont see an ItemTemplate for it.


Apr 23, 2009 at 4:13 AM
You will also have to do that through the ElementStyle and EditingElementStyle.

<Style TargetType=ComboBox>
<Setter Property="ItemTemplate">...</ >
Apr 23, 2009 at 5:57 AM
Thanks for the info.  I plugged that in but get an error says

Error 1 Cannot resolve the Style Property 'ItemTemplate'. Verify that the owning type is the Style's TargetType, or use Class.Property syntax to specify the Property. Line 500 Position 21. C:\MyStuff\Alexai\WpfApplication2\WpfApplication2\Window1.xaml 500 21 WpfApplication2

Here is the code for that one column

<dg:DataGridComboBoxColumn x:Name="colColumnType" Header="ColumnType" Width="100" SelectedItemBinding="{Binding ListCategoryID}" >
                        <Style TargetType="ComboBox">
                            <Setter Property="ItemTemplate">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBox Text="(Binding ListCategoryID}"></TextBox>
                                            <TextBox Text="(Binding CategoryName}"></TextBox>



Apr 23, 2009 at 9:38 PM
I think it should be on EditingElementStyle, not ElementStyle.  Try that out and let me know if you still have issues.