Click here to Skip to main content
12,951,548 members (53,339 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
i want to select a specified textbox like :

int k=15;
select textBoxk //  trying to select the textBox15


how can i select textBox15 with sending the number 15 from outside?
Posted 5-Jan-13 6:48am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

Try this:
Dictionary<string, TextBox> textBoxDictionary = new Dictionary<string, TextBox>();
public Form1() // constructor
{
      InitializeComponent();
      textBoxDictionary.Add("textBox1", textBox1);
      textBoxDictionary.Add("textBox2", textBox2);
      textBoxDictionary.Add("textBox3", textBox3);
      ...
}

Now, to set the text of a specific text box, try this:
int k = 15;
textBoxDictionary["textBox" + k.ToString()].Text = "some text";

Hope this helps.
  Permalink  
v2
Comments
ahmetkocadogan 5-Jan-13 13:58pm
   
thanks for the help
ProgramFOX 6-Jan-13 9:39am
   
You're welcome!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

i think it must be :
Dictionary<string,textbox> textBoxDictionary = new Dictionary<string,textbox>();

it says 'Type Expected' when i dont write TextBox.
am i right?
  Permalink  
Comments
ProgramFOX 5-Jan-13 13:07pm
   
Yes, you're right. I updated my answer, and I added <small>TextBox</small>.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Hi

You can use from bellow code:

-------------------------------------------------------------
TextBox[] textBox = new TextBox[NumberOfTextBoxYouNeed];
textBox[YourDestinationNumber].Text = "Your Text";



I hope it's helpful
  Permalink  
v2
Comments
ahmetkocadogan 5-Jan-13 14:59pm
   
thanks, this is helpful and very useful
Reza Alipour Fard 5-Jan-13 15:07pm
   
You're welcome. It is my pleasure. Best Wish for you.
ridoy 5-Jan-13 15:43pm
   
+5
Reza Alipour Fard 5-Jan-13 15:53pm
   
Thank you for attention
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

To set the value of the variable to the textbox, set textBoxk.Text = 15;
To set focus to a textbox, call textbox.Focus().
  Permalink  
Comments
ProgramFOX 5-Jan-13 12:56pm
   
The OP means that he want to get textBox15 if <small>k</small> is 15, and the OP want to get textBox14 is <small>k</small> is 14, ...

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,084
CHill60 3,480
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,830


Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 5 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100