1
votes

I have a requirement to generate a combobox inside the datagrid and bind the selected item. am binding the datagrid using a dictionary. the values are getting binded but not the selected item. here is my piece of code !

        private DataGridTemplateColumn CreateColumnEditTemplate(string fieldName, ObservableCollection<CommonFieldValue> fieldNames)
        {
        DataGridTemplateColumn outData = new DataGridTemplateColumn();
        StringBuilder xamlData = new StringBuilder();
        xamlData.Append("<DataTemplate ");
        xamlData.Append("xmlns='http://schemas.microsoft.com/winfx/");
        xamlData.Append("2006/xaml/presentation' ");
        xamlData.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
        xamlData.Append("xmlns:basics='clr-namespace:System.Windows.Controls;");
        xamlData.Append("assembly=System.Windows.Controls' >");
        xamlData.Append("<ComboBox SelectedItem='{Binding " + fieldName +                 ",Mode=TwoWay}' SelectedValuePath=\"Content\" >");
    foreach (var field in fieldNames)
        xamlData.Append("<ComboBoxItem Content='" + field.FieldValue + "'/>");
        xamlData.Append("</ComboBox> ");
        xamlData.Append("</DataTemplate>");
        outData.CellEditingTemplate =   (DataTemplate)System.Windows.Markup.XamlReader.Load(xamlData.ToString());
    return outData;
        }

am creating a template column and adding a datatemplate.

1

1 Answers

0
votes

Finally i found the answer on how to do it,

Dynamic Editable Fields Datagrid