Windows 8 - options how to save ListBox items so that when I close and open the app again the items are still there? - windows-8

Let's say I have a ListBox:
ListBox myListBox = new ListBox();
myListBox.Items.Add("One");
myListBox.Items.Add("Two");
myListBox.Items.Add("Three");
I need to save these items somewhere in the project so that the only way getting rid of it is to uninstall the app, is it possible?

If you have the items added as you have shown, you would have to first iterate the listbox to get the items in order to persist them. A better option is to have the items stored in an array/object/whatever elsewhere and use that array/object/whatever to both persist the list and to populate the listview.
Then, hook into the application Suspend event. In the event, you can persist the array/object/whatever to local storage or to the cloud, depending on what you want. You would then check on app resume/startup if persisted data was available and restore it if it is.
Some useful links:
Application.Suspending event
Guidelines for app suspend and resume
Part 2: Manage app lifecycle and state

Related

Event when VBA code module is reset?

I am developing an excel sheet which has lots of ActiveX elements in it.
I am not using UserForm and all the data is loaded when an activeX button is pressed.
At this point a hidden excel app is created where various actions are performed.
This new app is then combined with other data etc etc.. based on what the user is doing on the front-end with the provided ActiveX controls.
My problem comes when the "project is reset", where all the objects are released from memory and everything.
If this was a user form I would have implemented "on terminate" event where I would close hidden all workbooks that I have used, basically clean after myself.
However this is not a userform and there is no way to detect when the "project is reset"(as far as I know) so the hidden excel app that I've created remain open but nothing points to it.
If I go to the task manager i see various "EXCEL.EXE" and the number of those is basically the number of times I have run the tool.
So, is there any way for me to detect when VBA is about to "stop the project" in the same was as there is "terminate" for user forms so I can delete unsused stuff and reset elements in the spreadsheet?
Thank you!
I have found that there is no corresponding event to catch this.
Best way to handle this is to create a hidden userform object which will "hold" all global variables and objects that I define. I can then implement a UserForm_Deactivate event to catch when the form is exiting and clean up after myself.

Insert/Remove item in listbox bound to database

I want to be able to reorder my listbox which is bound to my sql ce database by clicking up and down arrow buttons. Since my listbox is populated directly from my database using the entity framework, I think I have to delete the object (from the listbox) and reinsert it (in the row above) if I want to move the item up the list.
I have no view model, my listbox is populated directly from my database in my code like this:
listBoxProperties.ItemsSource = entities.Properties.ToList();
Does my question make sense?
Cheers
ormally you would handle the moving of your list item in your view model which would hold the ObservableCollection the control was bound to - and then that would be reflected in your control via the binding.
It is going to get messy trying to accomplish this dirrectly on the control - which is your only way since your binding to a throwaway copy of the EF properties list.
As your UI dev goes on you are only going to run into more issues like this. I strongly recommend getting a view model in place sooner rather that later.

App responsiveness during loop

I have designed an app in vb.net 2005 that at one point adds and loops over about 500k list in listbox about.
When adding these items to the listbox, the app freezes for about 5-10 minutes, then when looping over the items, processing them, the app also freezes for the same time. Am loading the data from a text file
How can I make my application
responsive during loops?
should I use a queue to process the
list?
what is the messagequeue control
for?
I recommend you to use BackgroundWorker. Store items in array, and bind listbox to it. Working with array will be much faster then with listbox'es collection.
Or you can call BeginUpdate/EndUpdate before/after adding new items.

silverlight domain datasource refreshed only after F5

I am using SL4 with WCF RIA services. I have a domain datasource which I am using to populate a listbox.
I have attached a context menu attached to the list items that I want to trigger an update to a fields value in the database.
so I am trying
EmployeeDetail employee = (EmployeeDetail)sender;
if(employee.EmployeeDetails!=null)
employee.formEmployee.CommitEdit();
dsEmployee.SubmitChanges();
So the code works ok I see the update in the database, however the listbox hasn't been refreshed. If I press F5 then I see the change in the silverlight application however what do I need to do to refresh the lists datasource?
The question is a little bit vague. If your listbox is bound to a collection of EmployeeDetail objects, and they are entities, they will be wrapped in an IObservableCollection<EmployeeDetail>, which means that your listbox should be updated whenever your list is updated in the code behind. However, if you really need to refresh manually, I find that this works:
IObservableCollection<EmployeeDetail> temp = employeeListBox.ItemSource;
employeeListBox.ItemSource = null;
employeeListBox.ItemSource = temp;
If you want to manually refresh a DomainDataSource, you can use the Load() method. If you want to do it on every successful submission, you can subscribe to the SubmittedChanges event and immediately invoke a load.

Share Point Foundation 2010 - Failed to Start Workflow

I am using SharePoint Foundation (Sharepoint 2010) to develop a workflow in Visual Studio with an ASP.NET Workflow Initiation Form.
I use this form to set some properties on the share point list item on which the workflow instance is being started. Sometimes I get an Error message in the brwoser window, something like:
Error
Failed%20to%20Start%20Workflow
Troubleshoot issues with Microsoft SharePoint Foundation.
Correlation ID: 0b8e0b67-f824-4aa5-8316-424ada134f8d
Date and Time: 6/25/2010 10:59:17 AM
Go back to site
This behaviour seems intermittent. What's going on?
The problem is that the SharePoint workflow initiation form caches the workflow List Item on PageLoad, and when you make changes to the item between the page load and calling HandleStartWorkflow (i.e. clicking on the Start Workflow button), SharePoint freaks out that the item that you're talking about is different (the cached item) to the item that exists in Share Point (which incorporates the changes you've just made).
The general steps to reproduce the problem are:
Start the workflow so that the initiation form shows.
Change some property on the WorkflowProperties.Item
Call WorkflowProperties.Item.Update to save the changes to SharePoint
Call HandleStartWorkflow.
You will get the error.
The error may seem intermittent if some of the time the change to the workflow item properties is made in a separate page load 'session' to the session that the Start Workflow button is clicked. For example, if you PostBack some form data and then click the Start workflow button then everything works, because the PostBack happened and then the page was loaded.
But if you use an ASP TextBox OnTextChanged event, change the text and then click the Start Workflow button, the OnChanged event is fired AFTER the page is loaded with the old data, the data is changed to the new data and the workflow is started before the item data is re-loaded from SharePoint.
The fix is easy: Reload the workflow item data JUST before starting the workflow. This will cause your cached workflow item and the sharepoint version of the item to be the same, and share point will be happy.
In the "Workflow Initiation Code" region, change:
Private Sub StartListWorkflow()
Dim association As SPWorkflowAssociation = workflowList.WorkflowAssociations.Item(New Guid(associationGuid))
Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData)
SPUtility.Redirect(workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, System.Web.HttpContext.Current)
End Sub
to
Private Sub StartListWorkflow()
'Re-initialize the workflow parameters, particularly the workflowListItem, in case it has been changed since page load.'
InitializeParams()
Dim association As SPWorkflowAssociation = workflowList.WorkflowAssociations.Item(New Guid(associationGuid))
Web.Site.WorkflowManager.StartWorkflow(workflowListItem, association, GetInitiationData)
SPUtility.Redirect(workflowList.DefaultViewUrl, SPRedirectFlags.UseSource, System.Web.HttpContext.Current)
End Sub
And everything should start working again.
The same message you will get if you try to start workflow (through the custom init form) which is already running on the item. Solution here would be to check the state of the workflow on the item.