Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello again!

 

I am in a quandry. I have a tabcontrol, on which I create a few controls. One of those controls is a textbox, for use to input a string of data. The problem I am having is that of getting the data from it. The code i'm using is:

	//create new tabpage, name it and label it
	TabPage tbtemp = new TabPage("Report: " + strtemp[2]);
	tbtemp.Name = strtemp[5];

	clsReports MyReports = new clsReports();
	//create a new report
	MyReports.iReportNumber = int.Parse(strtemp[5]);			MyReports.strServerIP = strtemp[1];
	MyReports.strPlayerName = strtemp[2];
	MyReports.strReason = strtemp[3];
	MyReports.strExtra = strtemp[4];
			
	AllReports.Add(MyReports);
	tbReports.TabPages.Add(tbtemp);
	//start adding runtime controls
	Label lblServer = new Label();
	Label lblPlayer = new Label();
	Label lblReason = new Label();
	Label lblTime = new Label();
	TextBox txtPass = new TextBox();
	//start setting the labels values
	lblServer.Name = "lblServer" + strtemp[5];
	lblServer.Text = "Server: " + strtemp[1];
	lblServer.Location = new Point(10,16);
	lblServer.AutoSize = true;
	
	lblPlayer.Name = "lblPlayer" + strtemp[5];
	lblPlayer.Text = "Player: " + strtemp[2];
	lblPlayer.Location = new Point(10,48);
	lblPlayer.AutoSize = true;

	lblReason.Name = "lblReason" + strtemp[5];
	lblReason.Text = "Reason: " + strtemp[3];			             lblReason.Location = new Point(10,80);
	lblReason.AutoSize = true;

	lblTime.Name = "lblTime" + strtemp[5];
	lblTime.Text = " Submitted: " + strtemp[4];
	lblTime.Location = new Point(7, 112);
	lblTime.AutoSize = true;

	txtPass.Name = "txtPass" + strtemp[5];
	txtPass.Text = string.Empty;
	txtPass.Location = new Point(10,144);


	//add controls to the tabpage
	tbtemp.Controls.Add(lblServer);
	tbtemp.Controls.Add(lblPlayer);
	tbtemp.Controls.Add(lblReason);
	tbtemp.Controls.Add(lblTime);
	tbtemp.Controls.Add(txtPass);
	//finally show the controls
	lblServer.Show();
	lblReason.Show();
	lblPlayer.Show();
	lblTime.Show();
	txtPass.Show();

 

It's probably an easy solution, I googled for it but didn't find any answers for .NET. :(

 

Thanks guys!

 

-Sean

-Sean
Posted
Show the code where you are trying to get the data from the control. Is should be simple once you know the name you have given the control.

 

I know the name of the control, it would be

"txtPass" + creport.iReportNumber;

 

The problem I am having is how access it's data. Do I access it just like it was always there?

-Sean
Posted (edited)
You should be able to use something like

 

Dim str1 As String

str1 = tbtemp.Controls(txtPass & creport.iReportNumber).Text

 

That doesn't work... I get a compiler error.

 

--EDIT--

 

Ok, figured out how to do it. This is probably the worst way possible to do it, so if you know a better way PLEASE tell me!

 

Since there is only 1 textbox on each new tabpage I create I used the following:

string b = string.Empty;

foreach(Control a in tbselected.Controls)
{
if(a.GetType().ToString() == "System.Windows.Forms.TextBox")
{
	b = a.Text;
}
}

 

Glad I don't have many controls, or that would create some serious performance issues!

Edited by coldfusion244
-Sean

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...