Refresh information gotten from navigation property EF - wpf

I have an Enity Model contains a UsersList entity associated to UserTasks with UserID. UserTasks is loaded in a DataGrid, I'm getting the UserName from UsersList using NavigationProperty. I've made a simple ChildWindow linked to the DataGrid's SelectedItem to edit selected task including the user (which is my problem).
when selecting another user from a ComboBox and other information, All are updating normally in the DataGrid except the user Name.
I did debug to see if the UserTasks object got the new UserID, I found that it did.
What's missing to get DataGrid refresh the task's user name ?

Sorry, I resolved my problem I just missed to set UpdateSourceTrigger=PropertyChanged

Related

Vaadin: Reload ComboBox List while typing

I got a ComboBox in Vaadin and want to reload (from db) the set of entries in the dropdown list while typing in the text field of the ComboBox. I always got the exception:
java.lang.IllegalStateException: A connector should not be marked as dirty while a response is being written.
I tried to lock the session (getUI().getSession().getLockInstance().lock();), but it didn't help.
Is it possible to dynamically set/load the selection list of a ComboBox?
Cheers
Stefan
why do you want to change the content from DB as the user type? you'll get a postback and a query every key the user presses... isn't better to use the standard combo feature (which tries to autocomplete the value given what the user is typing)?
Anyway, if you really need this feature, you may extend the standard behaviour of combo extending the container behind the combo, as the data shown is taken from a container.

How to reset a viewmodel in mvvm

How can I reset my viewmodel when the user clicks new button on the view that has the viewmodel as it's datacontext?
For example:
If I have a view NewCustomer and upon save, the data is saved to the DB and the newly created account number is displayed. But when the user clicks the New button in the screen, I want the view (viewmodel) to be reinitialized. Or if the user clicked cancel in the screen to clear all changes.
How can I achieve this? I am using Prism 5.0 and Unity as my container.
If I used IRegionMemberLifetime, I can clear the viewmodel data when I navigate away and navigate again to the view (by setting the KeepAlive as false on clicking New button before navigating away). But I want the form to be cleared without navigating. Can this be done?
You could have a screen/workspaceViewModel, and another ViewModel wrapping your data.
So two classes: CarScreenViewModel and CarViewModel.
The CarScreenViewModel would have a property, say CurrentCar, which reflects what is currently selected in the screen. Then, when clicking the Create button, you simply set:
CurrentCar = new CarViewModel();
Resetting partially loaded data will only lead to behaviour that is hard to reproduce. It is better to start with a fresh instance.
Your standard approach will be something like below
ViewModels
CustomersContainerViewModel which contains
a collection of CustomerViewModel s
and ICommands like
CreateNewCustomer
DeleteExistingCustomer
UpdateExistingCustomer
Your View will contain
the CustomersContainerView which will contain
a collection of Customer Objects in your required UI element
a button to Create new customer (which will launch a new screen which contains the newCustomer fields it can also contain cancel, which will just close the form)
a button to delete (can also be a ContextMenu)
a button to update (can also be a ContextMenu) which will launch a customer form filled with details from DB.
Hopefully this makes some sense... Let me know if you have problem with any of the above
Update - Forgot to add. NewCustomer Command will add a new Customer object to your CustomerCollection and that should open a NewCustomer form (or whatever you chose) for user to input the customer details. Cancel/Delete will just remove that record from the collection. Delete will update the DB as well in addition
In my case
yourViewName.variableName.postValue("")

Refresh page after hitting the back button on widonws phone 7

I am developing a windows phone application. It's some kind of reminder which can have custom reminder categories. I am using the mvvm pattern.
I have two pages. One is for entering new data (category name and description) and editing and the other is for selecting a specific category wchich can then be edited/deleted.
The second page has a listbox which displays all categories that exist... after clicking on one of them the first page where the values (category name and description) are already entered in the textboxes. I can now edit and save them. All this works fine except for one thing. After saving and hitting the back button (so that i can get back to the list) i realize that the page isnt refreshing so that the old value is still displayed. How can i make the page "refresh" after poping up again...
Your description of the problem is a bit vague without any code or XAML. There are few things you need to check -
Check if the items in the page are databound properly
Check if you have implemented properties of the ViewModel(s) correctly. RaisePropertyChanged in the property's setter must be implemented.
Code/XAML snippets will help others identify your problem.

Problems with checkboxes in Datagrids

I am having some trouble with CheckBoxes in a DataGrid. The CheckBoxes are not bound to the entities that are populating the datagrid because there isn't a property on the entities for it. Basically what I am trying to do is when I check a CheckBox I add the ID of the item in that row to a list to be returned. The problem I am having is when I check some CheckBoxes and the page with the DataPager it uncheckes the CheckBoxes on the first page and tries to remove them but the DataGrid has already gone to the second page so it throws a null reference exception because it can't find those items anymore. How can I fix this? If you need me to post my code just let me know.
One approach to this is to customise the partial class that Entity Framework has created for you. Add your boolean property to the entity class. Now you can bind the checkbox column as any other column ant the data will be maintianed between paging.
You can then just enumerate through the items currently in the context select those have been checked.

Cannot tab out of databound Winforms dropdown list

This is a bit of a strange one, but I've been struggling for a few hours now and I can't understand what is happening.
I was wondering if anyone else has experienced this problem, and can perhaps explain it. I'm building a simple Winforms app and trying to use many of the built in controls.
Basically, I've got a form with a user control and some data capture fields. 3 of the fields are dropdown lists and on the user control I have a bindingSource control that binds directly to a Product class.
At run time I provide an instance of the Product class to the BindingSource and the class contains a property of ProductType. For simplicity I also added a List<ProductType> ProductTypes to the Product Class which loads itself when queried, which means I can just use the same bindingSource and choose the ProductTypes Data Member as the Datasource for the dropdownlist.
Upon running the form, the list binds perfectly and I can see all the product types listed, and I can select one and tab or click to the next field. But obviously the selected value won't bind because I've not chosen any bindings-SelectedValue for the dropdown, only a datasource. As soon as I make sure that the drop down modifies the instance of the Product by binding to the Bindings-SelectedValue, and then run the form, the list still gets populated perfectly and I can tab through the controls as long as I don't make a selection from the dropdown. If I make a selection from the dropdown then the dropdown holds focus. I cannot tab out for love or money and can't even click cancel button on the form, the close button top right is the only button I can click which works and I can't click any other field or dropdown. This affects all three dropdowns as soon as a selection is made.
Anyone have any ideas what I'm missing?
I have tried changing a few things and had some success by feeding the dropdown values a string[] instead of a member of an object. That seems to work, but defeats the object of using databinding doesn't it?
Any help appreciated!
Just guessing here, because I don't have time to set up a test and confirm right now, but are you doing any validating? I seem to remember that data-bound controls won't let you leave if the contents don't validate. Even if you aren't explicitly, try setting CausesValidation to False to see if there's any sort of validation going on behind the scenes, that might at least give you a hint.
Thanks for the input on this, helped me wrap my head around this.
In my case, it turns out that an exception was being thrown in one of the EventHadlers for my ComboBox.Validating event. It was hard to track down, because the IDE didn't show me that exception. I was able to modify the Exception behavior (in the debug menu) and have it show me any InvalidOperationException that was being thrown, and then I was able to track it down.
As Tom suggested, turning off CuasesValidation was the ticket to figuring it out.
For Infragisticst Dropdowns (may not be true for other winform dropdowns): If you have "LimitToList" set to true you can be stuck in a dropdown that you can't get out of without realizing it. Use the ItemNotInList even to trigger a warning message.

Resources