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
485
dynamically populated combobox in datagrid
posted

I have a XamComboEditor in my datagrid. I know how to add items to this in XAML (using ItemProvider and setting it to the EditorStyle) but what I really need is to be able to programmatically set the items of the combobox.. any ideas on how to do this?

  • 69686
    Verified Answer
    posted

     Hello,

    A quick way to do this is by create a new ComboBoxItemsProvider and then set it to the XamComboEditor's ItemsProvider Property like this:

     ComboBoxItemsProvider comboBoxItems = new ComboBoxItemsProvider();
                ObservableCollection<string> itemsCollection = new ObservableCollection<string>();
                itemsCollection .Add("1");
                itemsCollection .Add("2");
                itemsCollection .Add("3");
                comboBoxItems.ItemsSource = itemsCollection ;
                CellValuePresenter cvp = CellValuePresenter.FromRecordAndField(xamDG.Records[0] as DataRecord,xamDG.FieldLayouts[0].Fields[1]);

                XamComboEditor xce = cvp.Editor as XamComboEditor;
                xce.ItemsProvider = comboBoxItems;

                xce.SelectedIndex = 0; 

    Hope this helps.