Click here to Skip to main content
15,796,102 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a WPF app that manages people data. Each person has some attributes and a list of phone numbers. In the main window I have a DataGrid bound to a ObservableCollection, with the individual properties in a few DataGridTextColumn, and a Column with ComboBox, that each one displays each person's phone number list. By now, everything is perfect. What I want, then, is when clicking a MenuItem (that is OK) for edit a person's data, that a child Window opens, and that I have in some TextBox the current values of the person's individual attributes (which I can modify and save without problems) and a DataGrid that displays (1 or several rows with) 2 columns, with a data and the phone number, and a 3rd column with a Button (that's OK) for deleting the row. Here comes my problem. I want to populate this DataGrid, programmatically, by code, without any binding (it's not necesary), to display the person's current phone number list (that are 2 string by row), and also to be able to edit it in runtime (change cell values, add rows, and delete rows), in order to, then by clicking OK Button, update that person's phone number data list (by changing rows, adding, or deleting them) as well as his individual attributes. By now, I only was able to edit existing rows, with binding, but not to add nor delete. I already know how to deal with the database and ADO.NET and handling the program objects and data, I only need to know how populate the DataGrid without binding and to edit it in runtime.
I hope you can help me. I suspect this is much simpler than it seems to be.
Thank you very much in advance for your help

What I have tried:

I searched for a long while but what I saw is posts that said to use binding, and that without it, it was impossible to edit the DataGrid in runtime.
I tried for example:
foreach (TelData data in person.Tels.PhoneNbrs)
and I could see the rows fine, but I could not edit them.
I also tried handling the DataGrid RowEditEnding event (with binding), where I tried to add TelData objects to the source List by accessing the Item:
but it always was null
And I also tried accessing
to test the DeleteRow Button, and it was always null, too.
Definitely I searched a lot but curiously, with binding it is possible to edit existing rows but not to add nor delete without throwing an Exception.
Updated 28-Mar-23 7:29am

1 solution

Your "wants" are unreasonable, particularly since you already know how to work with an observable collection. You want a car that rolls without wheels. You can do it, but you'll need logs.

Pretend your NOT binding by throwing away the observable collection when you're done (and don't tell anyone).
Share this answer

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