I have a combobox that has items in it and I want to prevent the cursor from being able to leave the control if it fails a validation check (namely for valid file names). Basically the cursor can leave if the file is found.
I assume this needs to be done during the OnExit event.
How do I bring the focus back to the control if the validate conditions are not met?
Related
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).
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.
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.
I have a user control ProfileEditor in a WPF application. It has a number of input controls (TextBoxes, ComboBoxes, Radio Buttons, DatePicker). It will be used to add details for a new profile, or change details for an existing profile.
There is a requirement that if any changes have been made from the initial state (blank for a new profile, prefilled with current data for existing profile), if the user tries to leave the screen, they will first be warned that there are unsaved changes. This control will always be on a Page inside a Frame element, so leaving the screen will be either when navigating to a new Page in the Frame, or exiting the application.
What is the optimal setup for this?
I am thinking that there would be some event that would be attached to all data entry controls on the page (or maybe one event per control type) on the TextChanged or SelectionChanged events that would then set a page-level bool property as to whether or not changes have been made. Is there a way to set these using styles for all types of a control on the page at one time?
And then how would I catch the close screen event? Attach something to the Frame.Navigating event?
I have a text box on a form and want to perform different actions when it receives focus depending on how the focus was received.
If the user clicks on the text box I want the standard method where the cursor is placed at the end of the text string inside the box. If the user tabs to the text box I want all of the text contained within the text box to be selected.
Is there an elegant way to accomplish this?
I suppose one thing you could try would be to set some application-level (or parent-level) tunneling events so you can toggle a flag indicating it was mouse clicked or keyboard pressed (PreviewMouseDown and PreviewKeyDown). Depending on what was previously pressed by checking that flag, you could do the appropriate action when the text box gets focus.