(Using WPF application)
This is the situation:
There are 3 user input fields. 1 for hours, 1 for minutes and 1 for seconds.
Behind it is a checkbox for "divide time by half" that does nothing more than devide the timespan created by the user input by half.
But when the checkbox gets checked, i first make a check in the code if the user had put in any numbers in the fields: hours/minutes/seconds.
If all are 0, a messagebox pops up telling the user he needs to put in something.
But at this point, i want to "cancel" the checking of the checkbox.
Should i use something as e.Cancel or something ?
Or should i set the IsChecked back to false together with the messagebox ?
Im wondering wat the correct way of dealing with this is.
I think your approach is wrong.
The checkbox should enable only when there is valid input.
You could set a LostFocus event on your textboxes and inside that event check the all the input values.
If input is right then enable the checkbox else disable it. No need to cancel the checkmark
The action of clicking the checkbox has a two step behaviour:
Validating the time
Dividing it by half
If you want to maintain those two step in an unique operation the action of checking the checkbox in fact triggers the event, the validation step is performed, then you uncheck it. I think that from this perspective it is more correct to set checkbox.IsChecked to false.
As pointed out by Steve I would separate the validation step from the operation. Disable the checkbox when the input is not valid putting a check function on the TextChanged event of the textboxes. If everything is fine you can enable the CheckBox. If not disable it and uncheck it if it is checked.
Related
This is a concept question. I have a web form with 6 gridviews, below each gridview is a textbox. Each row of the gridview contains a question and 5 radio buttons. When a radio button is ticked or text is entered in the textbox it updates the database immediately with one caveat, the textbox is committed when the user presses the tab key, or refocuses curser outside the textbox, or clicks an unrelated button (basically when a postback or textchanged() event occurs).
The problem: There is a delay during postback when the text is committed to the database causing the user to think they can move to the next textbox only to have the curser return to the previous textbox. I added code to prevent the curser jumping but the delay is still an annoyance to users during testing. I added a confirmation message (label) to alert the user when it's ok to move on but when the confirmation message disappears at the next postback, usually when the user ticks the next radio button, the gridview shifts up and the user's curser is pointed to a different line of the grid. This is also annoying users.
Solutions? In my limited experience I have 2 alternatives maybe 3 (below). The reason I did not do either was because I wanted data to update the database as soon as it was typed or ticked. Since the radio buttons cause an immediate update I didn't want the users to inadvertently think the textboxes did too and forget to click a button to commit the text. Since entering text in the textboxes is optional, I don't have a way to validate if the user is done completing the form and remind them to click a button to commit their text input.
Put a button by each textbox to commit the text
Use one button to commit all textbox data when form is complete
Find a way to put a placeholder where the confirmation label is when its hidden so it doesn't shift on postback.
I'm starting to think one Submit button is the way to go and let the user think that is what saves the data? Simple.
At any rate is there a better way to achieve my goals of having input updated in database immediately without annoying delays (postbacks) and grid shifting at inopportune times?
In my case I changed the textbox AutoPostBack property to False and removed all code in the text_changed() event for all textboxes. I am committing the text when a Submit button is clicked. (The radio buttons still commit to db immediately when selected). In the end, I think users are conditioned to click a submit or save button when they finish filling out a form anyway.
Im trying to create a basic example sign up page.
I want the mouse pointer to enter the textbox only on click however it seems to enter the first textbox by default. What is the process to change this?
You could use the opacity and sets it to 0 together with the IsEnabled attribute which I would set to false.
Then you put in your click event this simple code.
textbox.Opacity="1";
textbox.IsEnabled="true";
I hope this helps you.
I'm a beginner at C# and I'm making this calculator and it has multiple text boxes for different calculations. I've assigned calculator button numbers (0-9) for user input. I can get the number buttons to work for the various textboxes but they are all inputted at the same time. I want to make it so that if a certain textbox is selected, then the user can start using the buttons. Any ideas?
Thanks
You can implement the OnFocus event of the corresponding TextBox. In the method you should set the Enable flag of the Button instance to true where they were originally set to false.
Furthermore you need to keep track of which Textbox was selected last, and redirect output to that one if the user clicks a Button.
I have a small problem. I have a TextBox myTxt. I set the myTxt_Leave event to check the database if input value already exists. If value exists, I display a MessageBox and set myTxt.Focus(). That wont let user to leave this TextBox, until another value (which does not exist in the database) is input.
But here is the catch...I would like to allow user to click on Cancel button on the form even if the value does not change. Is that possible?
Hope someone understands what I wanted to tell.
Thank you for any help.
EDIT:
I decided to change the interface a little. I put red label under the textbox "Value already exists" and disabled the Submit button until the value is correct.
But still, I'm curious if solution for my previous problem is possible?
Instead of binding the event to the Leave interaction, just Highlight the box in red and disable the submit. When the when the error is resolved or the action is cancelled, clear the red / disabled submit button.
I have a form where there is group of radio controls and some with textbox.
If the cursor is on textbox and i try switching the cursor to a different radio button, i should be able to identify the last active control( in this case.. the textbox) and do some validation.
The LostFocus() event of textbox pops up message indicating that "this item should be filled in..".
But if i want to go with a different radiobutton option in the same group, i dont want this message popping unnecessarily.
How do i avoid that?
The TextBox has Validating and Validated events-- you should use those instead of the LostFocus event. In the case of Validating, you can stop the user from leaving the TextBox if the criteria isn't correct. If you must use "something" like LostFocus, use the Leave event instead.
There is no "Last Active Control" type function. You would have to track that yourself by setting a variable on the Enter event of those controls.
That will lead to an ugly mess to maintain in my opinion. Validate at the form level is probably the best choice for the end user.