Вопрос

In my application I have two datagrids connected to DB by Entity Framework. First datagrid is used only to select worker, second datagrid is to add, remove, update previous selected workers training's. Please check the screenshot for better view.

Problem is that whenever I add or remove rows from second datagrid (with training's) It's not updating rows, it update database, but datagrid control stays the same. Modifying rows works good.

What I have done while trying to solve this: 1. Checking for stupid code mistakes (misspeling etc) 2. Force to update Itemsource with : OnPropertyChanged("ToolboxList"); 3. Breakpoint everything and it works...

But datagrid rows are the same...

Some clues that might be the reason but I am not sure if they are problem makers here:

  1. enovaWorkers its not a table its a view, hr_ToolboxTalk its a table, and because you can't make association view to table they are associated with one to many pragmatically inside EF edmx file.

  2. Second datagrid is not binded by selection from first datagrid (SelectedWorker.hr_ToolboxTalk) because whenever you want to edit row in second grid it raises Edit is not allowed exception. This is described here: master detail datagrid not editable

    And since I cant and don't want to edit entitiy framework tt file I made workaround with GetToolboxTalkList() method. So please check the code.

Pasted code (some sections are cuted):

XAML : pastebin.com/h3sdbfKm

ViewModel: pastebin.com/7Vj3P5UJ

ICommand class: pastebin.com/rQAh7FM9

Thanks for the help...

Это было полезно?

Решение

Change:

List<hr_ToolboxTalk> ToolboxList;

to:

ObservableCollection<hr_ToolboxTalk> ToolboxList;

It will work, Lists dont Notify to the view Automaticaly.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top