Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
110
Binding a Combo Box in the Edit Template
posted

I've managed to get a combo box to work as the editor for a field on my grid. However the only examples I have seen have the items hard coded in the XAML. I need the items in the combo box to be populated from a datasource - not the same one as the grid either.

I've spent a while trying to do this but seem to be nor further forwards.

 Can anyone help ?

 

  • 60
    posted

     Hi

    how did you manage to get a "plain" combo (not XamCombo) in your grid?

    Thank you very much

    Regards

    Klaus 

  • 275
    posted

    We add and bind our XamComboEditors like so in procedural code(C#):

    Field field = new Field();
    field.Name = fieldName;
    field.Label = label;
    field.Settings.EditorType = typeof(XamComboEditor);

    ComboBoxItemsProvider cbip = new ComboBoxItemsProvider();
    cbip.ItemsSource = data;
    cbip.DisplayMemberPath = displayField;
    cbip.ValuePath = valueField;
    cbipList.Add(cbip);

    Setter setter = new Setter();
    setter.Property = XamComboEditor.ItemsProviderProperty;
    setter.Value = cbip;

    Style style = new Style(typeof(XamComboEditor));
    style.Setters.Add(setter);
    field.Settings.EditorStyle = style;

    dataGrid.FieldLayouts[0].Fields.Add(field);

     

    Hope it helps!
    Mike

  • 2070
    posted

    Hi,

     

    One way you can do this is to add the data source to the Resources collection of the window or the data grid and then use DynamicResource syntax to set the ItemsSource property of the combo box to that data source.

     

    Hope this helps,

    Sandip