How can I use the loop indexing for a textbox's name?
-
Hello everyone, Here is my situation and I need your help guys. I have a loop to filter some data out of the DatGridView. I would like to assiagn each data to a specific TextBox (Five TextBox in total). The text boxs are names : textBox1 textBox2 textBox3 textBox4 textBox5 Can someone be kind enough to tell me how I can assiagn each data to a textbox according to its index? This is what I mean:
for (int i = 1; i <= 5; i++) { // I know that I cannot use this line but I am only trying to make myself undreestood.... // Can you tell me how I can achieve this? textBox[i].Text = foundRows[i].ToString(); }
Thank you very much and have a great day. Khoramdin -
Hello everyone, Here is my situation and I need your help guys. I have a loop to filter some data out of the DatGridView. I would like to assiagn each data to a specific TextBox (Five TextBox in total). The text boxs are names : textBox1 textBox2 textBox3 textBox4 textBox5 Can someone be kind enough to tell me how I can assiagn each data to a textbox according to its index? This is what I mean:
for (int i = 1; i <= 5; i++) { // I know that I cannot use this line but I am only trying to make myself undreestood.... // Can you tell me how I can achieve this? textBox[i].Text = foundRows[i].ToString(); }
Thank you very much and have a great day. Khoramdin -
Hello everyone, Here is my situation and I need your help guys. I have a loop to filter some data out of the DatGridView. I would like to assiagn each data to a specific TextBox (Five TextBox in total). The text boxs are names : textBox1 textBox2 textBox3 textBox4 textBox5 Can someone be kind enough to tell me how I can assiagn each data to a textbox according to its index? This is what I mean:
for (int i = 1; i <= 5; i++) { // I know that I cannot use this line but I am only trying to make myself undreestood.... // Can you tell me how I can achieve this? textBox[i].Text = foundRows[i].ToString(); }
Thank you very much and have a great day. KhoramdinLets say these 5 buttons are placed on Form1. Than you can write this: for(int i=1,i<6 i++) { Form1.Controls["textbox"+i.ToString()].Text=something; }
-
Hello everyone, Here is my situation and I need your help guys. I have a loop to filter some data out of the DatGridView. I would like to assiagn each data to a specific TextBox (Five TextBox in total). The text boxs are names : textBox1 textBox2 textBox3 textBox4 textBox5 Can someone be kind enough to tell me how I can assiagn each data to a textbox according to its index? This is what I mean:
for (int i = 1; i <= 5; i++) { // I know that I cannot use this line but I am only trying to make myself undreestood.... // Can you tell me how I can achieve this? textBox[i].Text = foundRows[i].ToString(); }
Thank you very much and have a great day. KhoramdinKhoramdin wrote:
textBox1 textBox2 textBox3 textBox4 textBox5
If you give them real names, they may make more sense. Then add a tag to each which is the same as the column you want to assign there, assuming they are columns from a single record. Then loop through the controls collection looking for the one with that tag. Or you can create an array of textboxes.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )