Click here to Skip to main content
15,881,881 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
I want to add controls dynamically to particular cell based on datagridcomboboxcolumn selected value. Please help
Posted
Comments
Sergey Alexandrovich Kryukov 5-Jan-16 2:18am    
What's the problem? This is done in the same way as any other ContentControl.
—SA
Member 10641344 5-Jan-16 6:20am    
I have a Datagrid with two columns. First one is DatagridComboboxColumn and the second one is DatagridTemplateColumn. Based on the first column cell selectedItem, I have to bind controls(it may be Label/textbox/combobox) in second column cell. I tried with frameworkelementfactory as below.

FrameworkElementFactory textFactory = new FrameworkElementFactory(typeof(StackPanel));
FrameworkElementFactory editView = new FrameworkElementFactory(typeof(Label));
editView.SetValue(Label.ContentProperty, "Do Nothing");
textFactory.AppendChild(editView);
DgTemplateColumn.CellTemplate = new DataTemplate(typeof(DataGridCell)) { VisualTree = textFactory };

With this code Label is getting displayed for the whole column. I want to show this in the corresponding cell.
Sergey Alexandrovich Kryukov 5-Jan-16 10:27am    
I answered in Solution 1. Isn't it clear enough?
—SA
Member 10641344 6-Jan-16 7:08am    
Didn't get you. Can you please give me a small example.
Sergey Alexandrovich Kryukov 6-Jan-16 9:57am    
myCell.Content = myGrid;
or
myCell.Content = myButton;
// ... :-)

—SA

1 solution

Please see my comment to the question. This is how: ContentControl.Content Property (System.Windows.Controls)[^].

You should understand that System.Windows.Controls.DataGridCell is System.Windows.Controls.ContentControl.

At this point, the solution should be pretty obvious to you, but if it's not quite clear yet, it means that you have to learn WPF content model better: WPF Content Model[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900