Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Settings a DataTemplate for a column programatically.

Sort Posts: Previous Next
  •  04-29-2007, 10:43 PM Post no. 7832

    Settings a DataTemplate for a column programatically.

    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;
  •  04-30-2007, 8:57 AM Post no. 7833 in reply to 7832

    Re: Settings a DataTemplate for a column programatically.

    The correct way would be:

    CellEditorBinding myCellEditorBinding = new CellEditorBinding();

    comboFactory.SetBinding(ComboBox.ItemsSourceProperty, myCellEditorBinding.ProvideValue( null ) );
    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
  •  04-30-2007, 11:13 PM Post no. 7834 in reply to 7833

    Re: Settings a DataTemplate for a column programatically.

    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
  •  05-01-2007, 7:57 AM Post no. 7835 in reply to 7834

    Re: Settings a DataTemplate for a column programatically.

    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!
    Marc Laroche
    Software Developer
    Xceed Software Inc.


    I don’t suffer from insanity, I enjoy every minute of it. - Unknown
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.