Q:

how to place comboxes in a datagrid when using itemsource binding c# and xaml

i want jobrole and jobtitle to be comboxes and buttons.
because it is generated with a itemsource binding and the list being generated in c#.
i can't find a way to be able to say if that column name is a Jobrole then make a combobox or some other method i don't know of.
if possible how to make a column only readable.
<Grid>
    <DataGrid ItemsSource="{Binding ContactList}" SelectedItem="{Binding SelectedContact}"/>
</Grid>

in case you need it, this is where my datagrid is made up.
public static ObservableCollection<ContactPerson> getContactPerson()
        {
            ObservableCollection<ContactPerson> contactPersons = new ObservableCollection<ContactPerson>();

            try
            {
                doc.Load("Database/contactpersoon.xml");
            }
            catch (Exception e)
            {
                throw;
            }

                XmlNodeList elemList = doc.GetElementsByTagName("contact");
                for (int i = 0; i < elemList.Count; i++)
                {
                    ContactPerson contactPerson = new ContactPerson();
                    contactPerson.ID = i.ToString();
                    contactPerson.Name = elemList[i]["name"].InnerText;
                    contactPerson.Company = elemList[i]["company"].InnerText;
                    contactPerson.City = elemList[i]["city"].InnerText;
                    contactPerson.Email = elemList[i]["email"].InnerText;
                    contactPerson.Phone = elemList[i]["phone"].InnerText;
                    contactPerson.Cellphone = elemList[i]["cellphone"].InnerText;
                    contactPerson.JobRole = new ContactPersonType
                    {
                        ID = i.ToString(),
                        Name = elemList[i]["jobrole"].InnerText
                    };
                    contactPerson.JobTitle = new ContactPersonTitle
                    {
                        ID = i.ToString(),
                        Name = elemList[i]["title"].InnerText
                    };

                    ContactPersonTitle.invullenContactPersonTitle(i.ToString(), contactPerson.JobTitle.Name);

                    contactPersons.Add(contactPerson);
                }

            return contactPersons;
        }

    public override string ToString()
    {
        return ID + " " + Name + " " + Company + " " + JobRole +" " + JobTitle + " " + City +" " + Email + " " + Phone + " " + Cellphone;
    }

thanks

A:

There is a DataGridComboBoxColumn that you can use. Something like this:
<DataGrid.Columns>
    <DataGridComboBoxColumn Header="Job Title"
                            DisplayMemberPath="JobTitle.Name"
                            ItemsSource="{x:Static ContactPersonTitle.AvailableJobTitles}"
                            SelectedItemBinding="{Binding JobTitle}"/>
</DataGrid.Columns>

But this means that you'll need to set AutoGenerateColumns="False" for the data grid so as not to generate this column. And that, in its turn, means that you'll need to set all other columns.
I've assumed a static property (with change notification) on ContactPersonTitle object, since you already have a static method there. If you want to use a list from the view model, it should look something like this:
<DataGrid.Columns>
    <DataGridComboBoxColumn Header="Job Title"
                            DisplayMemberPath="JobTitle.Name"
                            ItemsSource="{Binding RelativeSource={RelativeSource FindAncestor,
                                                      AncestorType={x:Type UserControl}},
                                                  Path=DataContext.AvailableJobTitlesInViewModel}"
                            SelectedItemBinding="{Binding JobTitle}"/>
</DataGrid.Columns>

If you need more refined control over how the data is displayed, you can use DataGridTemplateColumn that will allow you to set CellTemplate and CellEditingTemplate - both data templates that you can customize to your needs. The data context for these data templates is the item of the row, i.e. ContactPerson in your case.

