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

  • Home
  • SEARCH
  • 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 580503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:28:48+00:00 2026-05-13T14:28:48+00:00

I have a list of custom objects: say Fruits with two string properties Name

  • 0

I have a list of custom objects: say Fruits with two string properties Name and Color. These are in a List.

private readonly List<Fruit> fruitList = new List<Fruit>();

Then I load fruit objects into the list.

I am trying to bind this list to WPF Datagrid:

C#:

dgFruit.ItemsSource = "{Binding}";

XAML:

<toolkit:DataGrid Name="dgFruit" 
            ItemsSource="{Binding Path=fruitList}" >
                <toolkit:DataGrid.Columns>

                    <toolkit:DataGridComboBoxColumn 
            Header="Name" 
            SelectedValueBinding="{Binding Path=Name}" 
            TextBinding="{Binding Path=Name}" Width="5*" />   

                    <toolkit:DataGridComboBoxColumn 
            Header="Color"
            SelectedValueBinding="{Binding Path=Color}"
            TextBinding="{Binding Path=Color}" Width="5*" />

                </toolkit:DataGrid.Columns>
            </toolkit:DataGrid>

Reason they are in a combobox is because I want user to be able to change the relationship. This is not the real example but you get the idea. Say for the sake of the example the fruit wasn’t ripe so they change Banana color to green 🙂

I’m not having any luck getting these items in the datagrid… and down the track, I want a click on the item in the datagridcell to change to combobox and show all possible types of Fruit Names and Colors (so they can change the relationships)

Here is an error i’m getting:

System.Windows.Data Error: 39 : BindingExpression path error: 'Color' property not found on 'object' ''Char' (HashCode=6750311)'. BindingExpression:Path=Color; DataItem='Char' (HashCode=6750311); target element is 'TextBlockComboBox' (Name=''); target property is 'Text' (type 'String')

Can anyone help? The reason i am setting my colums up in xaml is so i can set width to star size and have the columns equal width.

I see most examples use an ObservableCollection but if I can bind to list why do I have to use this?

Please let me knwo if my example requires further clarification

Edit: what I have now:

XAML:

            <toolkit:DataGrid Name="dgFruit" 
            ItemsSource="{Binding}"
            AutoGenerateColumns="False">

                <toolkit:DataGrid.Columns>
                    <toolkit:DataGridTextColumn 
                        Header="Name"
                        Width="5*"/>

                    <toolkit:DataGridComboBoxColumn 
            Header="Color"
            Width="5*"/>

                    </toolkit:DataGrid.Columns>
</toolkit:DataGrid>

C#:

DataContext = fruitList;

Actually when I use DataContext I get no items. When I use ItemSource I get blank lines, but the correct number of rows so this seems more along the right lines.

I can get the data to show if I let it Auto generate columns. If I set autogeneratecolumns to false and then specify my columns in xaml like i want to to use star sizing, I get the right number of columns but no text!

  • 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-13T14:28:49+00:00Added an answer on May 13, 2026 at 2:28 pm

    First, this:

    dgFruit.ItemsSource = "{Binding}"
    

    should set the items source to a string containing the word Binding in braces. This is almost certainly not what you want (in fact, if you do this you should end up with a grid with nine rows, one for each character in the string!). You can set the ItemsSource in the XAML, or the code behind, but you shouldn’t do both. Try the following:

    <toolkit:DataGrid Name="dgFruit"       
                      ItemsSource="{Binding}">
        ...
    </toolkit:DataGrid>
    

    And then in your visual’s constructor:

    ...
        InitializeComponents();
        this.DataContext = fruitList;
    ...
    

    Now the data context for your whole visual is the List<Fruit>, and the ItemsSource of your grid is set to be the same object. I’m assuming here that fruitList is a field of the visual itself.

    The bindings for your columns should look something like:

            <toolkit:DataGridTextColumn Header="Name"
                                        Binding="{Binding Name}"
                                        Width="5*" />
            <toolkit:DataGridComboBoxColumn Header="Color"
                                            ItemsSource="{Binding Source={StaticResource AllColors}}"
                                            SelectedValueBinding="{Binding Path=Color}"
                                            TextBinding="{Binding Path=Color}"
                                            Width="5*" />
    

    Where AllColors is defined as a resource (in this case):

    <x:Array x:Key="AllColors"
             Type="sys:String">
        <sys:String>Orange</sys:String>
        <sys:String>Yellow</sys:String>
    </x:Array>
    

    This should get you started.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of custom objects with two properties as identifiers (IDa and
I have a list of custom objects List and I would like to update
I have a strongly typed list of custom objects, MyObject , which has a
I have a custom query which eventually returns a list of objects. I need
I have a list of custom objects which I have added to a ListBox
I have a list of custom objects that I am loading into an ActivityList
I have a CustomObject, say defined with following attibutes: string Name {get;set;} string EmailAddress{get;set;}
I have a DataGridView with its datasource set to a generic list of custom
I have defined a custom Sharepoint list for special attributes related to a software
I have a custom class Contact . I am trying to bind a List<Contact>

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.