problem in implementing validations in dynamically generated textboxes in Desktop vb.net application
-
Hello coders, I am getting one problem in the saving the items information. I have taken one textbox for the NumberOfAssets based on which further generates the respective textboxes. And Before saving the information, I want to implement the validation check on those dynamically generated textboxes i.e. those textboxes must not be empty. For instance, If I enter 3 (integer value) in the "NumberOfAssets" textbox, it further generates the 3 textboxes, And before saving the window form, there must be a validation check for those 3 textboxes. I could not come up with the solution that how to put the validation using For Loop and where to do it as well.. please help ...
-
Hello coders, I am getting one problem in the saving the items information. I have taken one textbox for the NumberOfAssets based on which further generates the respective textboxes. And Before saving the information, I want to implement the validation check on those dynamically generated textboxes i.e. those textboxes must not be empty. For instance, If I enter 3 (integer value) in the "NumberOfAssets" textbox, it further generates the 3 textboxes, And before saving the window form, there must be a validation check for those 3 textboxes. I could not come up with the solution that how to put the validation using For Loop and where to do it as well.. please help ...
Hi, You'd need to hook up the
Validating
[^] event. Below is an example on validating a control from that event;void onValidating(object sender, CancelEventArgs e)
{
TextBox senderBox = sender as TextBox;if (senderBox.Text.Length == 0) { e.Cancel = true; System.Media.SystemSounds.Beep.Play(); }
}
..and this is the code to hook up the event. You'd need something similar to this in your
For
-loop.myTextBox.Validating += new CancelEventHandler(onValidating);
Good luck :)
I are Troll :suss: