Click here to Skip to main content
15,042,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
how can I save the Items of a DataGrid to a text file.

I watched several Tutorials - where to start?

Inotifychange? updateSourceTrigger? rowcolumnEnding? CellColumnEnding?

When I edit a cell in a datagrid a ObservableCollection will not be updated
only when I trigger the Collection with update?

Any help?

What I have tried:

ObservableCollection<observ> GetData()
            {
                using (var writer = new StreamWriter("text.txt"))
                {
                    foreach (observ item in datagrid)
                    {
                        writer.WriteLine(item.ToString());
                    }
                }

               return dglist;
            }
Posted
Updated 15-Jul-21 3:04am
Comments
Richard Deeming 15-Jul-21 3:46am
   
Your code seems to be very confused. What does returning an ObservableCollection have to do with writing text to a file? And where is the dglist variable defined?

1 solution

Bind the DataGrid to an ObservableCollection like in this example:
How to: Create and Bind to an ObservableCollection - WPF .NET Framework | Microsoft Docs[^]

And save the ObservableCollection like in the example here:
c# - Writing the contents of an ObservableCollection to a text file - Stack Overflow[^]
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900