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.
Related
I have a visual web part (sandboxed) that visualize a form for adding sub-sites. When a sub-site is added its added in the navigation and in a DropDownlist (for delete purpose...).
My problem is that after post-back everything works fine, except i have to manually reload the page to see the new changes (both nav. and dropdownlist). Note that neither Response.Redirect or UpdatePanel will work i a sandboxed-solution.
Anyone got a solution to this problem?
When you perform a postback, your browser submits the contents of all web controls to the server. The server is stateless in this sense; the state of the control is actually stored in your browser. I would say your problem occurs because the web controls are not populated from SharePoint object model. Instead, the server uses the data received as the postback. Alternatively, the population might even happen, but the postback data will overwrite the contents of controls.
The solution is to refresh control data after the controls have been populated from the postback data. You could do this, for example, in the method OnPreRender. When OnPreRender is called, all the postback data has already been processed.
Try to add the following code in your webpart class.
protected override void OnPreRender(EventArgs args)
{
if (this.Page.IsPostBack)
{
// Repopulate controls here
}
}
The problem of this is, of course, that repopulation will kill the previous (postback) state of the controls. So, if you want to preserve the current value of a control (such as a dropdown selection), you must save it before repopulation and restore it manually.
To learn more about the page lifecycle in ASP.NET, see ASP.NET Page Life Cycle Overview.
I am using Access for a quick and dirty (ADP) interface for an SQL (Express 2012) database so data entry can begin before the MVC web app interface is complete.
There is one field I want to be varchar, I would like this field to either allow the user to type in a value or select from a distinct list of values previously used in that field.
I have that part down, but the problem is when it happens, I have to refresh the recordset to see the new item in the list, so if they choose add a new record, then the last item added is not visible in the list.
So I can get the distinct list, populate the box, allow for new entry, and save that to the DB, do I have to write a code behind to repopulate the recordset, do I need to write a code behind to maintain the list paralleled to the recordset, or is there just a property I am missing?
Thanks
(Added screen showing event)
As suggested, using the on current event on the form and the after update solved the problem.
Clicking the form section detail selected the detail sections property page not the form. Selecting the form from the drop down on the property page displayed the events I was suggested to use.
Many thanks to those contributing.
As the first suggestion of this was from Remau, with assist in locating that event from hansup, I will mark remau's post as answer. Thank you to both.
Don't requery the form, just requery the combo. The best bet is probably the current event which will work if more than one person is doing data entry. It will also work if people are editing the table as well as entering data. Events that only fire when a record is added will not pick up changes to the combo contents.
Private Sub Form_Current()
Me.MyCombo.Requery
End Sub
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.
i have a silverlight application.In this i have used service file for DML operations.The methods in Service can be accesed in form page.ie the the XAML page(example Main.XAML)
MY issue is i cant access my DB in the XAML pages as it is in silverlight,i want to create a method in Service file,get some data from MAster tables and fill it in the combo boxes which are there in my first form.
Im trying to use System.Windows.Forms.ComboBox combobox as a control as i cant access the controls of my forms in the service file and then trying to use this control in my form(Main.xaml)then it is showing an error.
Can anyone please let me know how can i populate data this way in combo box.
Rply as early as posible.
You'll need to add an operation to your service that returns a collection of data contracts (for instance a collection of products).
Then call the service from your SL application using an asynchronous call and bind the data to the combo box in the async callback.
There's a working example here.
I am writing a program in VB.Net to manage text messages sent through an API. It allows you to view messages in a datagridview and filter by date, sent/unsent etc...
To load the messages I'm executing an SQL statement and retrieving a DataTable which then gets set as the DataSource for my DataGridView control.
The problem is that depending on the filters selected the user could be selecting a lot of records and it would take some time for the DataSource to update. I want to inform the user of this load time by providing a progress bar or label of some kind.
I have used progress bars before when looping through data but this is loading it all at once. I thought of displaying a label when the user clicks to load the data and then hiding it when the data is loaded. But this happens instantaneously even when the data is still loading.
Is there an event on the DataGridView I can use perhaps? Something like .DataSourceLoadStart and .DataSourceLoadFinished.
I know I'm just making those events up... but hopefully it makes it clearer as to what I want.
You could set the label to be visible when load is clicked and try the: DataGridView.DataBindingComplete Event to hide it, this event gets called when the binding is complete.
MSDN Link - DataBindingComplete
A little off topic but... I wonder if you could attach a AJAX update panel with activity/loading image to a gridview? I don't think I've ever seen it done but here's a great application for it.