Refresh Data in ComboBox List - winforms

I have a datatable (jobs) with a column in this table called StatusId. I have another datatable (jobStatus). The job table has 1 job record and the jobstatus table has all the job status.
On my winforms form I have the job record displayed and the job status is a combobox displaying the contents of the jobstatus table. The List portion (DisplayMember) is bound to the jobstatus table and the data portion is bound to the jobs table. (ValueMember) So all works well and when my jobs are selected and displayed the combobox selects the respective job status...All good.
Now I have another form (JobStatus) where I can added more job status records. So while I am entering / changing job records I discover I need another job status, so I jump over to my job status form and enter my new status. I then jump back to the job form and I now want to be able to select my new job status in the combobox.
My questions is what is the best practice for this senario where new records have been added or edited to a lookup style list which is used to populate a combobox on another form. I have tried putting code in the activate event of the form which works except the form flickers and it looks a ugly.
Any ideas???
I was virtually doing what your said, which made me look a bit closer at the code. The issue was the order I was processing the lines of code, and I found that when
old code
cboCustomer.DataSource = Business.Contact.GetContact( Enums.ContactType.Customer ).Tables[0];
sorted = ( ( DataTable ) cboCustomer.DataSource ).DefaultView;
sorted.Sort = "Name ASC";
new code here
DataView dv = Business.Contact.GetContact( Enums.ContactType.Customer ).Tables[0].DefaultView;
dv.Sort = "Name ASC";
DataTable dt = dv.ToTable();
cboCustomer.DataSource = dt;
works like a charm. Cheers for your help

You should be able to use the Activated event without a problem. That's even what the documentation says it is good for:
You can use this event for tasks such as updating the contents of the form based on changes made to the form's data when the form was not activated.
Of course, you'll get a few false positives when you subscribe to this event on the parent form. Consider the case where the user switches to the form without attempting to use the combo box control. It's not a huge deal, but in that case you will have updated the combo box for no reason. This is easily fixed by switching to handling the Enter event for the combo box control. This one only gets raised when that specific control receives the focus. The only limitation of the Enter event is that you can't change the focused control from inside of this event handler (but you don't want to do that anyway).
So now we need a fix for the flicker problem, which I think you'll find to be pleasantly simple. At the beginning of the event handler method (regardless of which one you use), before you start updating the combo box, call its BeginUpdate method. This prevents the control from flickering while it is being updated (by suppressing painting). At the end, you need to finish with a call to EndUpdate, which reenables painting and performs a single repaint to reflect your changes.
I just tested this myself, and I don't see any flicker. The most you'll get is a single flicker while the control gets repainted to reflect your changes. Obviously, you can't do any better than that.

Related

Write conflict on updating form checkbox with multi-table view as recordsouce

I have created a form with a View as recordsource, this view combines 1 table and another view (with 2 tables in it).
When the checkbox is clicked a validation happens in the Access code that checks if the records checkbox may be updated, if this is not the case then the checkbox value should change back to 0/false.
First I tried to do this simply in the click event of the checkbox and then setting the checkbox value = false when it does not validate. This however gives a write conflict. Next I tried it with a Me.Dirty = false in front of it, this also doesn't help (still getting the write conflict). The checkbox.undo gives the same result.
Then I thought to do it in the before update and use a simple cancel=true, this however causes the focus not to change (it keeps the focus on the same record and never moves from it).
The Timestamp is usually what I use to ignore write conflict messages, I included the timestamp of the main table but this doesn't work (probably because the view is multiple-table based).
Some additional info:
The view is created in the SQL server and is linked to Access
The primary keys of the view (so it is editable) are set by executing a CREATE UNIQUE INDEX statement
Any ideas how I can get this to work?
Fixed it by using a button to set the checkbox bound field to checked/unchecked and making the checkbox itself invisible. This seems to work (better).

Kendo UI DataSource toJSON is behind by a value

I have an angular application where I am trying to create batch editing in a Kendo Grid. I am manually adding data to the grid, so not using the datasource's transport mechanism, but rather just calling the .data() on the datasource.
When I edit a cell it correctly fires the save event, which also passes the modified data item, however when I call .toJSON() in order to get the raw data of the model, the output of .toJSON() seems to be different from the output of the model itself. It is as if the .toJSON() is behind by an iteration because when I edit the cell again it's the previous value I get.
An example of it can be seen here: http://dojo.telerik.com/ujiSu/5
Try to edit the product name, then in the console you can see the output of model and the output of model.toJSON()
I have tried calling .read() on the datasource before .toJSON() but that results in the datasource being emptied for some reason.
I have also been looking at the dirty property of the model data, forcing it's dirty state to change, but also without any different results.
My goal is to get the raw current data which is displayed in the grid and the datasource.
Any help with this is much appreciated.
In the save event of the grid, the model has not yet been updated. It will be updated by the grid(i.e. pushed into the grid's dataSource) after the save event. This is because the save event is cancel-able via e.preventDefault().
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-save
So, e.model contains the current state of the dataSource item and e.values contains the updated fields until after the save completes, at which point the values in e.values are pushed into the dataSource model.
You either need to combine e.values with e.model in the grid save event or you may want to instead look at the DataSource change event http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#events-change where the action is "itemchange" as that will occur after the grid save event(as long as you haven't cancelled it).

BreezeJS Entity keeps getting refreshed?

I have a page with two panels. The first panel is where create and update happens, and the second panel is a list of stuff that I just added. Sort of like this (below). The second panel updates the list every X second.
Each list has an edit button that takes it back to the first panel. I pass the entity through the button's function and fill up the values in the edit panel. Here's the weird thing, when I try like say edit an entity in the list, an the interval happens to update the list, the entity gets refreshed and all my changes are never saved.
I tried just passing the id though the button then doing a get request for that particular entity and performing the edit, but the interval takes place and my changes are reverted.
I think my only option is to do angular.copy(myEntity) and do the edits from there, and then manually do the PUT request. Is there another way for the edited entity not to be affected by the interval aside from doing an angular.copy()? Pausing the interval while something is being edited is not an option, since client wants the list to update even when he's editing something.
If you need to keep your data up to date by refreshing every few seconds, i recommend implementing a bool HasChanges() function in your controller. This will return true if the data has changed, and false if not. That way you can decide if you want to pull and refresh new data, or deffer it until your editing is done without overwriting your unsaved changes.

How to allow/stop an event based on a condition like YES or NO?

I need to allow or stop an event from happening, based on a given condition such as a pop up box with options YES, NO and CANCEL.
I need to notify the user saying that there are unsaved data and if the user wishes to SAVE it, IGNORE it or CANCEL his current action(event such as Selection-change or Click).
I tried to use createInterceptor() function. But could not achieve the functionality.
Can anybody give me some suggestions with example? Basically I want to know how to stop an event.
Thanks..
Edited
I like the idea of using beforeXXX events. But I am still facing problems. As I mentioned, I need to ask the user if he wishes to save the unsaved data, which is a popup message box (With options YES, NO and CANCEL) that runs asynchronously. So by the time I get a reply, the event will have happened.
For ex. lets imagine a situation where, there is a page that displays a list of records in a grid with a pagination toolbar attached to it on the bottom(with a page size of 10 and total number pages is 10. So totally 100 records) on the left hand side. If you select a record in the list, the details are shown in a detail view on the right hand side.
Now,
I select third record in the list and make some changes to it in the detail view(form).
Without saving the record, I click on next page button on the Pagination toolbar.
It will show a confirm box from the beforeXXX event of Pagination toolbar, but the event will have happened anyway.
Here if the user clicks on CANCEL, I will have to restore the previous state which is already gone. Somehow I will have to go back and select the third record in the list of previous page.
So in order to resolve this problem, if I return false from my beforeXXX event, the next XXX event will be not be triggered.
But if the user clicks on YES or NO options I will have to trigger the event XXX manually which I am unable to do it for a selection-change event as of now.
Like this there can be many operations like list-filtering, searching, Ordering(A-Z/ Z-A), logout etc. For each of this operation I will have to write customised code which totally spoils the readability of the code.
So I was thinking if there is way to, somehow manually trigger the event XXX by holding the event object in beforeXXX...or is there any other way to restore the previous state.
Please give me suggestions....Thanks...
Many events have their "before-" counterpart, for example "beforeactivate". If you return false from this kind of the processing stops.
If not, or if your event does not have it's before- part, then you can use event object passed to all event handlers and call:
ev.stopEvent();
ev.stopPropagation();
return false;
at the end of your handler.

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