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 Mahadak136 reputationPosted Feb 15, 2013, 9:47 PM EST
Sudhakar ChaudharyRank #1,379 · 1.2K reputationPosted Jan 27, 2013, 5:14 AM EST
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 = "";
}
}
}
}
}
kedar pawgi18 reputationPosted Jan 27, 2013, 7:40 AM EST
Thanks Sudhakar
kedar pawgi18 reputationPosted Feb 15, 2013, 5:47 PM EST
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 pawgi18 reputationPosted Feb 16, 2013, 4:50 AM EST
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.