Reset function with checkboxes in Struts 1.3 - struts

I've got a problem. I heard something about the Struts reset function but I never see any example and I don't know how to write it.
I heard it can help when I have such a case:
I have few checkboxes checked, then in my form I click next and go to next page, then I click back and go again to the page with checkboxes, uncheck few of them and check the others and click next again. Then, validation errors appear as if I those checkboxes which I unchecked were still checked.
Do you know how to use it in this case?

In the action form you can override the reset() method and initialize the checkbox property value to its default state. This only needed if your action form is session scoped. Thus it could contain values of the unchecked checkboxes before you submit or reset button pressed.
You can see the example Struts <html:checkbox> checkbox example.

Related

Having a problem with visual studio Databinding when leaving and coming back to the same form

For making this simply I have two forms a button on each to navigate between the two forms. Then on one I have a checkbox and label when the checkbox is checked it displays the label by using the following code in the form.load event:
Me.label1.DataBindings.Add("Visible", Me.checkbox1, "Checked")
The problem is if I were to leave the form with the checkbox and label and the checkbox is not checked and then I come back to the form with the checkbox and try and check it the label doesn't show up any suggestions or solutions.
Delete that line of code from the form load
Open your form in the designer, the one with the label and the checkbox on it
Click the checkbox
In the Properties grid expand (PropertyBinding) and open the drop down next to (none), click New at the bottom
Pick an initial value, and choose a name for the setting. Make it user scoped if you want to be able to save it and restore it next time the program opens
Now go to your label, properties, click the [...] next to (PropertyBinding) to see a list of all bindable properties, scroll to Visible and drop down to choose the same setting
Run the program.
Side note; when I did this I think I may have encountered a bug/feature of databinding (that I plan to research more) in that the behavior was only as expected if the bool starts out as true (so the control is visible) when the binding is set up. If the control is invisible, it never binds properly to see when the property has become true - so as a workaround (purely in this case where we're binding Visible), replace he call to InitializeComponent() with this, in the form's constructor:
if (!Properties.Settings.Default.FormatWithoutConfirmation)
{
Properties.Settings.Default.FormatWithoutConfirmation = true;
InitializeComponent();
Properties.Settings.Default.FormatWithoutConfirmation = false;
}
else
InitializeComponent();

How to see if ComboBox is in DropDown State?

I have searched several forums but did not find answer for checking whether ComboBox is already DroppedDown via VBA code.
I have other code on Form_KeyDown events due to which anytime I press vbKeyDown it moves to next record. I need to check if ComboBox is DroppedDown then don't use other code and instead treat the default functionality of access where vbKeyDown will start scrolling through the items of ComboBox displayed in DropDown.
There is no such property, neither an event for OnDropDown or similar.
If the combobox has focus, you can force a dropdown using the DropDown method, but that's as close you can get.

How to correctly close a Windows.Forms dialog and return something different than "Cancel"?

I defined a form which I show as a dialog as per myForm.ShowDialog. The form sets the AcceptButton property correctly to my button. When I call the Close() method, the dialog result is always Cancel.
I searched about this issue and found this question where they suggest to manually set DialogResult when it should be different to Cancel.
Since VB.net offers me to set an "Accept" button I find this "solution" quite hackish though. The documentation for the AcceptButton property says that it determines which button is "clicked" when the user presses the Enter key. I also expected that would automatically set the DialogResult to "OK" but it does not seem to do so.
So, is manually figuring out which button was clicked and updating the DialogResult, which looks like cleaning up after the Microsoft guys who designed Windows Forms, the way to go or did I miss something?
The AcceptButton does not close the form automatically. This is because it is just the default button which gets "clicked" if you press Return. If you set the DialogResult in the buttons click event handler, the form gets closed directly so you don't need to call .Close() anymore, so this seems not to be a bug to me.

how to prevent checkbox change event in vb.net desktop application

I have a checkbox in my vb.net desktop application,on check change event iam performing some action.i want that on pageload check change event should not fire and it shows checkbox.checked on gui.
Windows sometimes fires an event during form load, for whatever reason. It's really irritating, as you may have noticed. This is "by design" according to Microsoft.
You can initialize a variable (global or static), such as a boolean called "Loading" for example, to true. Then, in the form Shown event reset it to false. In the beginning of the event handler, check that variable and exit whenever Loading is true.
I bet you are creating the checkbox and after that you are setting it to checked.
You should create it already checked.
would be nice if you post the code how you create that checkbox and set it true.
You could use the Click Event of CheckBox and 100% safe every time the checkBox is changing state

vb.net getsettings

I need a form width a checkbox "Don't show this again" for my winform,
but how can i make this so when my Form1 loads it checks the state of the checkbox using the getsettings option?
How can is save the checkbox state to the registery? and how do i get the state?
If Form2.Checkbox.checked = Getsettings() Then
Form2.showdialog
Else
Goto Skip
End IF
Skip:
Windows Forms has built-in support for that, you don't need to write any code. Select your check box. In the Properties window, scroll to the top on expand the "ApplicationSettings" node. Click on "Checked" and drop-down the combobox. Click New. Set the Name property to something meaningful.
Done. Your check box will always restore with the last selection that the user selected. Don't call Show() when it is turned on, dispose the form right away.
The main crux of the question is "how do I read and write value to and from the registry."
See here for a great overview complete with code.
You're beginner so here are a few tips on your code sample:
Name your objects more verbosely. Form2 will mean nothing to you a few hours from now.
Do not use Goto. Just don't. Please. You either show the dialog or you don't. The whole Else block with the Goto in it is just not necessary.
Few more things you'll need to do to get this working:
Handle the CheckBox checked event and write either a 1 or 0 (or T or F) to a registry value
Read that registry value in your GetSettings method
You might want to pass a parameter to GetSettings that specifies exactly which setting you need because you'll probably want to reuse that method for other settings as well