Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,
can anyone tell me ..
How to get the value of all control of form and concate it using c#?
Posted

You can use a foreach loop to iterate all the child controls.
 
Share this answer
 
Comments
Mahesh_Bhosale 22-Mar-13 7:47am    
Thank you for reply.

I had get all controls of form by using following code..

public static List<control> GetControls(Control form)
{
var controlList = new List<control>();

foreach (Control childControl in form.Controls)
{
//Recurse child controls.
controlList.AddRange(GetControls(childControl));
controlList.Add(childControl);
}
return controlList;
}
List<control> availControls = GetControls(this);

But I cant understand how to get the values of them
like if control is textbox then textbox.text, if control is checkbox then true or false like these.
I am newer in C# if u know then please help me..
Richard MacCutchan 22-Mar-13 8:00am    
You need to check the type of control (as described here), cast it to the relevant type and then obtain its value. Maybe if you explained exactly why you need to do this someone could offer some more useful assistance.
Mahesh_Bhosale 23-Mar-13 1:19am    
Hi friend,
i simply making one user control named as toolbar.dll. the toolbar contain the add, save, update, delete and search button. to save the data of the form i want to use save button globally. for that firstly i had done the table mapping.

But i cant understand how to get the values of all control of active form and concate it. The concatenation string pass in save query.
If u know then please help me.
Richard MacCutchan 23-Mar-13 5:42am    
Sorry, but I don't understand what you mean by concatenate the values. I have shown you how to iterate the controls, and you can then query the name of each control and its status, but what you do with that information is not clear.
You can use a foreach loop if all child controls in single container but if you are using multiple containers then you have to also look inside these controls.
 
Share this answer
 
Comments
Mahesh_Bhosale 22-Mar-13 7:48am    
Thank you for reply.

I had get all controls of from by using following code..

public static List<control> GetControls(Control form)
{
var controlList = new List<control>();

foreach (Control childControl in form.Controls)
{
//Recurse child controls.
controlList.AddRange(GetControls(childControl));
controlList.Add(childControl);
}
return controlList;
}
List<control> availControls = GetControls(this);

But I cant understand how to get the values of them
like if control is textbox then textbox.text, if control is checkbox then true or false like these.
I am newer in C# if u know then please help me..
Nasir M@hmood 22-Mar-13 8:01am    
Let you want to grab textbox
foreach (Control childControl in form.Controls)
{
string strvalue ="";
if(childControl ==typeof(TextBox))
{
value +=((TextBox)childControl).Text;
}

}
Mahesh_Bhosale 23-Mar-13 1:11am    
its work friend, but how to get the checkbox value and how to concat the all values means in one string i want to concate the value of textbox, checkbox, datetimePicker and all other controls

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900