Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Indirect reference to controls or binding to arraylist i
Message
 
To
26/08/2008 18:25:11
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
C# 2.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01341965
Message ID:
01342824
Views:
18
Hi Tim,

You're back to my rescue again. What would I do without you? I think this will take care of my problem and is something that I'll still understand when I look at it 2 years from now and need to make some changes. The only downside I can see to this is that I would have to cycle through all the controls for each record in my table. Using your example, I guess I can test for a match on the 'txtSpecial' part of the name and based on that last part of the name, assign the value based on an array element with that same number. Thanks.

UPDATE: I did get this to work. I limited the number of controls I have to search through by putting them in an mmgroupbox and used an arraylist to make it easier to work backwords from the control name to the correct text value.


>Hi Linda,
>
>>I have a Windows form on which I need to display a series of text boxes, each displaying the value of a field from a different row of the dataset. In FoxPro, one way I have done is by using a macro to get an indirect reference to the text box name.
>>
>>For example:
>>
>>
>>* Using the indirect reference
>>lcBaseName = "TypeDesc"
>>lcRowCount = 1
>>use myTable
>>scan
>>    lcCurrentTextBox = lcBaseName + str(lnRowCount)
>>    &lcCurrentTextBox.Value = myTable.TypeDesc
>>endfor
>>
>>
>>
>>In .NET, I tried creating a variable with a type of Control and building it's name property using a counter but I couldn't get that to work.
>>
>>The other way I have done this in FoxPro is to set the ControlSource to an element of an array built from the table. In .NET, I tried creating an arraylist from the table and assigning an element to the BindingSource and the Text properties (not at the same time) with no success.
>>
>>Does anyone have any suggestions? I really don't want to hard code this if I can avoid it.
>>
>>Thanks in advance.
>
>You can reference controls with something like this:
>If you have a textbox named "txtSpecial1" you could find it with this and change it's text property.
>
>int i = 1;
>foreach (Control c in Controls)
>{
>     if (c is TextBox)
>     {
>          if (c.Name == "txtSpecial" + i.ToString()
>          {
>               c.Text = "MyText" + i.ToString();
>          }
>     }
>}
>
>
>I hope that helps to get you started.
>Tim
Linda Harmes
HiBit Technologies, Inc.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform