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 7989623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:48:21+00:00 2026-06-04T12:48:21+00:00

I’m got a collection of object and inside the object there are going to

  • 0

I’m got a collection of object and inside the object there are going to be some properties and a dynamic list of objects. I’m my example this is illustrated with the Name and Numbers properties.

Now I got it to look right, but I’m having problems changing the data from code behind.
If I change something in the mList inside the MainWindow() it’s correctly beeing displayed on my DataGrid, but If I do the same inside a Click even’t nothing happens.

I have looked at INotifyPropertyChanged, but that did’nt changed nothing.

Please not that this is a sample project I created for this question

MyList.cs

public class MyObject : IEnumerable<object[]>
{
    public string Name { get; set; }
    public int[] Numbers { get; set; }

    public IEnumerator<object[]> GetEnumerator()
    {
        var obj = new object[Numbers.Length + 1];
        obj[0] = Name;
        for (var i = 0; i < Numbers.Length; i++)
            obj[i + 1] = Numbers[i];

        yield return obj;
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
}

MainWindow.xaml.cs

private List<MyObject> mList;
    public MainWindow()
    {
        InitializeComponent();

        mList = new List<MyObject>
                    {
                        new MyObject {Name = "List 1", Numbers = new[] {1, 2, 3, 4}},
                        new MyObject {Name = "List 2", Numbers = new[] {1, 2, 3, 4}},
                        new MyObject {Name = "List 3", Numbers = new[] {1, 2, 3, 4}}
                    };

        dataGrid.ItemsSource = mList;
        var columnNames = new[] {"List", "Number 1", "Number 2", "Number 3", "Number 4"};
        AddColumns(dataGrid, columnNames);

        mList[0].Name = "Test";   //Works
        mList[0].Numbers[0] = 123;  //Works

    }
    private void AddColumns(DataGrid gv, string[] columnNames)
    {
        for (int i = 0; i < columnNames.Length; i++)
            gv.Columns.Add(new DataGridTextColumn()
                               {
                                   Header = columnNames[i],
                                   Binding = new Binding(String.Format("[{0}]", i))
                               });

    }

    private void ButtonClick(object sender, RoutedEventArgs e)
    {
        mList[0].Name = "Test test";   //Don't work
        mList[0].Numbers[0] = 234;  //Don't work
    }
}

MainWindow.xaml

<StackPanel>
    <Button Click="ButtonClick">Test</Button>
    <DataGrid Height="Auto" Name="dataGrid" AutoGenerateColumns="False"/>
</StackPanel>

EDIT
This is a mofidifed MyObject, I’m still not able to change the Name from code

 public class MyObject : IEnumerable<object[]>, INotifyPropertyChanged
{
    private string _name;
    public string Name
    {
        get { return _name; }
        set { _name = value;
            OnPropertyChanged("Name");
        }
    }

    public int[] Numbers { get; set; }

    public IEnumerator<object[]> GetEnumerator()
    {
        var obj = new object[Numbers.Length + 1];
        obj[0] = Name;
        for (var i = 0; i < Numbers.Length; i++)
            obj[i + 1] = Numbers[i];

        yield return obj;
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }

    public event PropertyChangedEventHandler PropertyChanged;
    protected void OnPropertyChanged(string name)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(name));
        }
    }
}
  • 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-06-04T12:48:23+00:00Added an answer on June 4, 2026 at 12:48 pm

    The problem is that with the following code

    Binding = new Binding(String.Format("[{0}]", i))
    

    you bind each column to a Path like [i].

    For example in the case of column 0 (binding to property Name) you need

    new Binding("Name")
    

    With this code you should see your datagrid update after executing

    mList[0].Name = "Test test";  
    

    The same concept is valid for the other columns

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

Sidebar

Related Questions

i got an object with contents of html markup in it, for example: string
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.