Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 918023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:18:17+00:00 2026-05-15T18:18:17+00:00

Question : Most code samples on the DataGridComboBox seem to use a static resource

  • 0

Question: Most code samples on the DataGridComboBox seem to use a static resource as the ItemsSource. In my use case, I’d like to provide different ItemsSources with each bound object. Can this be done?

Background: I’m trying to bind a collection of Question class objects to a WPF DataGrid, using a DataGridComboBoxColumn control. The Answer string provides the SelectedValue. I’d like the AnswerDomain list to provide the ItemsSource for each ComboBox. The AnswerDomain differs from Question to Question.

Class

public class Question
  {
    string Answer {get; set;}
    List<string> AnswerDomain {get; set;}
    //...other stuff
  }

XAML

<DataGrid ItemsSource="{Binding Path=InspectionItems}" AutoGenerateColumns="False" Name="dataGrid1" >
    <DataGrid.Columns>
        <DataGridComboBoxColumn Header="Answer Domain"
                                DisplayMemberPath="Answer"
                                SelectedValuePath="Answer"
                                ItemsSource="{Binding Path=AnswerDomain}" 
                                    >
        </DataGridComboBoxColumn>
    </DataGrid.Columns>
</DataGrid>

Problem: There are a couple problems. The key issue right now is that the ComboBoxes in each DataGrid Row aren’t displaying the AnswerDomain strings. I’ve tried a series of XAML combinations without success. Help me Stack Overflow.

UPDATE: The selected solution below worked. After some further fumbling and by adding UpdateSourceTrigger=PropertyChanged to the SelectedItem, user changes in the combobox were then reflected back in the underlying custom object.

<DataGridTemplateColumn Header="Answer">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ComboBox 
                ItemsSource="{Binding AnswerDomain}" 
                SelectedItem="{Binding Answer, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:18:17+00:00Added an answer on May 15, 2026 at 6:18 pm

    Your problem is that the display member path isn’t Answer because there is no “Answer” property off of a string. I never use the DataGridComboBoxColumn, it doesn’t seem natural to me, too much like the old win forms way. Try the below instead. BUT MAKE SURE YOU IMPLEMENT INotifyPropertyChanged on your Question Class, and fire the appropriate events.

    <DataGridTemplateColumn>
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <ComboBox ItemsSource="{Binding AnswerDomain}" SelectedItem="{Binding Answer}" />
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn> 
    

    Here is how your Question class should look:

    public class Question : INotifyPropertyChanged
    {
        private string m_Answer;
        public string Answer
        {
            get { return m_Answer; }
            set
            {
                if (m_Answer != value)
                {
                    m_Answer = value;
                    FirePropertyChanged("Answer");
                }
            }
        }
    
        private List<string> m_AnswerDomain;
        public List<string> AnswerDomain
        {
            get { return m_AnswerDomain; }
            set
            {
                if (m_AnswerDomain != value)
                {
                    m_AnswerDomain = value;
                    FirePropertyChanged("AnswerDomain");
                }
            }
        }
    
    
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;
    
        private void FirePropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While most code samples around the net use a static declaration of DependencyProperties, I
Title is most of the question, what allows this to be valid code? Is
My question may seem a little weird but I am sure most of you
Many iPhone code samples (from Apple, etc.) include code like this: - (void)viewDidLoad {
This question most closely relates to the asp.net mvc3 framework. It started out as
One more question about most elegant and simple implementation of element combinations in F#.
This not a programming question but Most of the programmers using Eclipse should have
This is probably a trivial question for most but here goes... I am using
Excuse me for what I'm sure is an elementary question for most of you,
I'm new in this subject so this might be a silly question for most

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.