Hi i need help regarding creating code reuse. I am developing desktop application where there are lots of form. In every form there are many textboxes, dropdown list box, i have button for adding new record . When i click "new" button for adding new record, what i do first is clear the contents of the textboxes and dropdown box(code is like ---- txtName.text=" ",txtAddr.text="",cbSupplierName.text="" to give some example). I do this thing for every form where i have to add new record. i do whole thing for every form. The help i want is how can i use the same code for every form or is there any way i can just get rid of this type of way of coding. Please guide me.. It becomes very tiresome to do the same code again and again.
Thanks in Advance.
Loading
Gopal MahadakPosted Feb 16, 2013, 2:47 AM
kedar pawgiPosted Feb 16, 2013, 9:50 AM
for your reply.
I have used the code given by you and it worked nicely i added combobox into it and it worked too..
Thanks for the answer.
kedar pawgiPosted Feb 15, 2013, 10:47 PM
Thanks for ur correct answer. I have accepted it. When i run code it work perfect. But when i put into my own project but it doesnt work because the reason i found was i put all my textbox and combobox in GroupBox. Thats why this code dont work on it. Can you give me some solution for this, otherwise ur code id perfect and works fine. But i need these stuff in GroupBox.
Thanks in Advance...
kedar pawgiPosted Jan 27, 2013, 12:40 PM
Thanks Sudhakar
Sudhakar ChaudharyPosted Jan 27, 2013, 10:14 AM
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace clear
{
class ClassClear
{
public static void ClearTxtCom(System.Windows.Forms.Form fm)
{
foreach (Control ctr in fm.Controls)
{
if (ctr is TextBox)
{
ctr.Text = "";
}
else if (ctr is ComboBox)
{
ctr.Text = "";
}
}
}
}
}