View Single Post
  #6 (permalink)  
Old 28th February, 2007, 12:55 AM
Gizmo's Avatar
Gizmo Gizmo is offline
Chief BBS Administrator
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 14,946
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

The basic idea would be like this:

Assuming that you have a tab control, each tab on the tab control will itself also contain controls. Therefor, you iterate over each control on the tab, looking for the ones that are TextBox controls, like so:

Code:
	private void button1_Click(object sender, System.EventArgs e)
	{
		double sum=0.0;

		foreach (Control ctrl in this.tabpage1.Controls)
		{
			if(ctrl.GetType().FullName == "System.Windows.Forms.TextBox"
				sum=Read_textboxes(ctrl);
		}
		MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
	}
	private double Read_textboxes (TextBox txtbox)
	{
		try
		{
        			return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
		}
		catch
		{
			return 0.0;
		}
	}
}
I hope this answers your question. As I said before, though, this could potentially be a horrid way of approaching the problem. It only really works if you can constrain the containing control so that it only contains textboxes. The easy way to do that would be to add a GroupBox control to the tab and place all of your TextBoxes inside that GroupBox.

Assuming you did the above, and placed all of the controls on tabpage1, inside a GroupBox called groupbox1, the code would look like this:

Code:
	private void button1_Click(object sender, System.EventArgs e)
	{
		double sum=0.0;

		foreach (Control ctrl in this.tabpage1.groupbox1.Controls)
		{
			if(ctrl.GetType().FullName == "System.Windows.Forms.TextBox"
				sum=Read_textboxes(ctrl);
		}
		MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
	}
	private double Read_textboxes (TextBox txtbox)
	{
		try
		{
        			return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
		}
		catch
		{
			return 0.0;
		}
	}
}
So it is still the same idea, just one extra level of controls to reference.

Hope that helps.
__________________
Avatar and sig graphic by Pitch. Subscribers!
Ask about a custom graphic or avatar today!
 
Later,
Gizmo
Thermal Diode Mod and Direct-Die Water Block
8-Cheetah 18GiB U-2 SCSI
MegaRAID Enterprise 1500/128MiB
Samsung SyncMaster 955DF
TTGI/Superflower TTS-520 PSU
 

 
AOA Team filesAOA Team wcgAOA Team fah
Reply With Quote