Home Forums WPF controls Xceed DataGrid for WPF Settings a DataTemplate for a column programatically.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22893 |

    Hello,
    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.

    Thanks,
    Greg

    List<string> strings = new List<string>();
    strings.Add(“Fred”);
    strings.Add(“Sammy”);

    Binding itemsBinding = new Binding();
    itemsBinding.Source = strings;

    FrameworkElementFactory comboFactory = new FrameworkElementFactory(typeof(ComboBox));
    comboFactory.SetBinding(ComboBox.ItemsSourceProperty, itemsBinding);
    //comboFactory.SetValue( //HERE IS WHERE I ASSUME THE BINDING SHOULD GO

    DataTemplate template = new DataTemplate(typeof(ComboBox));
    template.VisualTree = comboFactory;

    grdMain.Columns[0].CellEditor.EditTemplate = template;

    Imported from legacy forums. Posted by Greg (had 3023 views)

    Xceed Support
    Member
    Post 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)
    Member
    Post 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?

    Thanks,
    Greg

    Imported from legacy forums. Posted by Greg (had 464 views)

    Xceed Support
    Member
    Post 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)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.