|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Loops and textboxesI have created a class that inherits from the dictionary base, and i have 10
text boxes on my form, these are labelled txtPrice0 to txtPrice9. I have populated my class with values from a database. I want to be able to get the values from my class into the text value of each box. Each value in my class has a key from 0 to 9 i thought about using a textbox object e.g. dim txt as new textbox but then i got confused and wasn't sure where to go with it. Basically i want to loop through my dictionary putting the value into the appropriate box. can anyone help me please TIA hi Steven,
In MFC there was a very handy function called GetDlgItem and you could obtain a pointer to the required text box etc. So you could simply say CTextBox* pText = (CTextBox *)GetDlgItem(txtPrice0) and then set the desired text. In .net its not simple but you can still do it. You can use the "Controls" collection. Try the following code (C#) foreach(Control ctrl in Controls) { if(ctrl is TextBox && ctrl.Name == textBoxName) { ((TextBox)ctrl).Text = value from dictionary; } } In the above you have to make sure textBoxName is generated as txtPrice0 etc. So the above loop will be run as many times as the number of text boxes you have. Hope this helps. Seshagiri -- Show quoteSeshagiri Cherukuri "steven scaife" wrote: > I have created a class that inherits from the dictionary base, and i have 10 > text boxes on my form, these are labelled txtPrice0 to txtPrice9. I have > populated my class with values from a database. I want to be able to get the > values from my class into the text value of each box. > > Each value in my class has a key from 0 to 9 i thought about using a textbox > object e.g. > > dim txt as new textbox > > but then i got confused and wasn't sure where to go with it. Basically i > want to loop through my dictionary putting the value into the appropriate box. > > can anyone help me please > > TIA > |
|||||||||||||||||||||||