Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Monday, October 31, 2016 1:46 AM
I want to add a reset button on Windows Form. One Windows Form contains only a DataGridView and other one contains only TextBoxes. How could I do that?
Thank you
Faisal
All replies (8)
Monday, October 31, 2016 3:44 AM ✅Answered | 1 vote
On the Form with TextBoxes.
For Each Ctl As TextBox In Me.Controls.OfType(Of TextBox)
Ctl.Clear
Next
On the Form with DataGridView you don't explain how it gets Columns and Rows, if it is bound to a DataTable or anything so how can anybody know? The below code will set DataGridView so nothing is in it unless it is bound.
DataGridView1.Rows.Clear
DataGridView1.Columns.Clear
DataGridView1.Refresh
La vida loca
Monday, October 31, 2016 4:08 AM ✅Answered | 1 vote
Actually what I am asking is I want to add a button that will clear all the inputs added by user from a Windows Form, or the Windows Form will be back to its original state when I click it.
Is this your startup form, or a form you open from your startup form? If it's your startup form and you want to clear everything then the simplest and quickest is to restart. This will set everything, not just control properties, back to their design values. See:
https://msdn.microsoft.com/en-us/library/system.windows.forms.application.restart%28v=vs.110%29.aspx
If this is a form that you open from the startup form, then just create a new instance:
Dim MyNewForm as New Form2
MyNewForm.Show
Monday, October 31, 2016 2:00 AM
Hi
A 'Reset' button is just another button. Add it in the same way you added all those other control - textboxes and DataGrid(View?)
*
OR
*
are you asking about some code you want the 'Reset' button to perform?
Regards Les, Livingston, Scotland
Monday, October 31, 2016 2:03 AM
Hi
A 'Reset' button is just another button. Add it in the same way you added all those other control - textboxes and DataGrid(View?)
*
OR
*
are you asking about some code you want the 'Reset' button to perform?
Regards Les, Livingston, Scotland
Yes, I am asking about some code.
Faisal
Monday, October 31, 2016 2:42 AM
Hi
A 'Reset' button is just another button. Add it in the same way you added all those other control - textboxes and DataGrid(View?)
*
OR
*
are you asking about some code you want the 'Reset' button to perform?
Regards Les, Livingston, Scotland
Yes, I am asking about some code.
Faisal
Hi
How about some code to reset your micowave oven, or perhaps to reset your bathroom tiles maybe? There are quite a few things that can be reset. Which particular thing do you want to reset?
Regards Les, Livingston, Scotland
Monday, October 31, 2016 3:01 AM
Hi
A 'Reset' button is just another button. Add it in the same way you added all those other control - textboxes and DataGrid(View?)
*
OR
*
are you asking about some code you want the 'Reset' button to perform?
Regards Les, Livingston, Scotland
Yes, I am asking about some code.
Faisal
Hi
How about some code to reset your micowave oven, or perhaps to reset your bathroom tiles maybe? There are quite a few things that can be reset. Which particular thing do you want to reset?
Regards Les, Livingston, Scotland
Haha. Actually what I am asking is I want to add a button that will clear all the inputs added by user from a Windows Form, or the Windows Form will be back to its original state when I click it.Is it possible?
Faisal
Monday, October 31, 2016 8:26 AM
On the Form with TextBoxes.
For Each Ctl As TextBox In Me.Controls.OfType(Of TextBox) Ctl.Clear NextOn the Form with DataGridView you don't explain how it gets Columns and Rows, if it is bound to a DataTable or anything so how can anybody know? The below code will set DataGridView so nothing is in it unless it is bound.
DataGridView1.Rows.Clear DataGridView1.Columns.Clear DataGridView1.RefreshLa vida loca
Thank you. Just what I wanted.
Faisal
Monday, October 31, 2016 8:27 AM
Actually what I am asking is I want to add a button that will clear all the inputs added by user from a Windows Form, or the Windows Form will be back to its original state when I click it.
Is this your startup form, or a form you open from your startup form? If it's your startup form and you want to clear everything then the simplest and quickest is to restart. This will set everything, not just control properties, back to their design values. See:
https://msdn.microsoft.com/en-us/library/system.windows.forms.application.restart%28v=vs.110%29.aspxIf this is a form that you open from the startup form, then just create a new instance:
Dim MyNewForm as New Form2
MyNewForm.Show
Thanks a lot. Working like a charm.
Faisal