User (Old forums)MemberApril 29, 2007 at 10:43 pmPost count: 23064
I have been attempting to set a data template for a column of a grid programatically and have run into the problem of binding the templates value to the value in the grid. In Xaml you would use CellEditorBinding as the Value of the template to bind to the cell data. I have not found a way to do this binding through code. Any help would be appreciated.
Below is the code I am using the create my test.
List<string> strings = new List<string>();
Binding itemsBinding = new Binding();
itemsBinding.Source = strings;
FrameworkElementFactory comboFactory = new FrameworkElementFactory(typeof(ComboBox));
//comboFactory.SetValue( //HERE IS WHERE I ASSUME THE BINDING SHOULD GO
DataTemplate template = new DataTemplate(typeof(ComboBox));
template.VisualTree = comboFactory;
grdMain.Columns.CellEditor.EditTemplate = template;
Imported from legacy forums. Posted by Greg (had 3023 views)Xceed SupportMemberApril 30, 2007 at 8:57 amPost count: 5658
The correct way would be:
CellEditorBinding myCellEditorBinding = new CellEditorBinding();
comboFactory.SetBinding(ComboBox.ItemsSourceProperty, myCellEditorBinding.ProvideValue( null ) );
Imported from legacy forums. Posted by Marcus [Xceed] (had 504 views)User (Old forums)MemberApril 30, 2007 at 11:13 pmPost count: 23064
Thank you for the response. A few questions about it though.
I have been unable to find an object in your library called CellEditorBinding, what assembly is it included in?
Second, this seems to disregard the ability to fill the combo box with items, if we use the binding property rather than the value property of the Factory how can the items of the combo box be filled?
Imported from legacy forums. Posted by Greg (had 464 views)Xceed SupportMemberMay 1, 2007 at 7:57 amPost count: 5658
First of all… I misspelled the name of the object… my mystake…
The full name of the class is Xceed.Wpf.DataGrid.Markup.CellEditorBindingExtension (it is a markup extension, therefore, in XAML, we do not need to write the “Extension” part ).
Secondly… In fact, I guess what you could do is bind the ItemsSource property to any data source (as required for your needs)… The important thing would be to use the CellEditorBinding to bind the SelectedValue, SelectedIndex or SelectedItem property.
That should do the trick!
Imported from legacy forums. Posted by Marcus [Xceed] (had 5077 views)
- You must be logged in to reply to this topic.