Adding New Item To BusinessList Doesn't Refresh View

Sep 12, 2011 at 2:57 AM

I have a view with a listbox bound to business list base on the left and the contents of the business base on the right.  As I scroll down the list, I can edit all the child items individually.  There is an add new button under the listbox allowing me to add a new item to the business list.  Clicking the button causes a trigger action to call a method on the ViewModel which calls the "AddNew" method on the list.  I can see that the new business object is created when I click on the button, but the list in the view is never updated.  What I would like to happen is the new business object would be added to the bottom of the list and the focus would be set to the first textbox on the right side of the list so the data can be typed in.  What do I need to do to refresh the listbox? 

Sep 13, 2011 at 2:08 AM

It turns out that I had two instances of the business object, so when adding items to the business list they were not being seen because they were directed to a second instance.  Getting rid of the second collection view source instance solved the problem.

Sep 13, 2011 at 9:54 PM

Part II - Now that I have my new item added to the bottom of my list, I set it as the currently selected item and then set focus to the first editable text boxes:

        public void AddNewProblem(Bxf.Xaml.TriggerAction sender, Bxf.Xaml.ExecuteEventArgs args)
            if (args.MethodParameter != null && Model != null)
                MaintenanceProblemList maintenanceProblemList = (MaintenanceProblemList)args.MethodParameter;
                maintenanceProblemList.AddedNew += maintenanceProblemList_AddedNew;

        void maintenanceProblemList_AddedNew(object sender, Csla.Core.AddedNewEventArgs<MaintenanceProblemItem> e)
            MainPage mainPage = (MainPage) Application.Current.RootVisual;
            MaintenanceRootView rootView = (MaintenanceRootView)mainPage.contentControl1.Content;
            rootView.ProblemList.SelectedItem = e.NewObject;


Is there a better way to get a handle to the View?  I would thing the ViewModel should have a "View" property just like it has a "Model" property...but I can't figure it out.

Sep 20, 2011 at 1:08 PM

I propose you open a new thread called something like 'How to set focus to a control?', because this is a common question.

Btw, You should unregister the AddedNew handler in maintenanceProblemList_AddedNew...