473,511 Members | 14,933 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing textboxes created in code in vb2010

1 New Member
Hi. Relatively new to vb2010 so if this is easy then I apologise in advance.

The following code creates textboxes on a form according to the contents of an array named ProdName.

The array; along with "intCount"; is declared in another form named WNew as "Public Shared".

intCount is used to count the number of products entered in WNew and is therefore used to tell this form how many textboxes to create in the loop.

The "tbName" textboxes contain the information drawn from the ProdName array in WNew - and (miraculously) this works!

Where I'm going with this is that when the blank textboxes "tbCrates" are produced alongside the "tbName" boxes the user enters a figure in these boxes. Ideally I need that entered figure stored in an array; but everything I've tried so far fails because I'm struggling to access coded textboxes.

In an Ideal world, if ProdName(1) is, let's say, "Bike" and the user types in 15, then a "Quantity" array should show 15 in Quantity(1).

Does anyone have a solution? I should stress that this is not for commercial purposes but is purely something I'm working on for myself for personal use and to help me learn how to program.

Expand|Select|Wrap|Line Numbers
  1. Public Shared tb(100) As TextBox
  2.     Dim Crates(100) As String
  3.     Dim n As Integer = 1
  4.     Dim r As Integer = 176
  5.     Dim t As Integer = 1
  6.  
  7.  
  8.  Private Sub WPurchases_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.  
  10.      If WNew.ProdName(1) <> "" Then
  11.             For i = 1 To WNew.intCount
  12.  
  13.  
  14.                 tb(n) = New TextBox
  15.                 tb(n).Name = "tbName" & n.ToString
  16.                 tb(n).Text = WNew.ProdName(n)
  17.                 tb(n).Size = New Size(148, 20)
  18.                 tb(n).Location = New Point(21, r)
  19.                 tb(n).BorderStyle = BorderStyle.Fixed3D
  20.                 Me.Controls.Add(tb(n))
  21.                 tb(t) = New TextBox
  22.                 tb(t).Name = "tbCrates" & n.ToString
  23.                 tb(t).Size = New Size(55, 20)
  24.                 tb(t).Location = New Point(175, r)
  25.                 tb(t).BorderStyle = BorderStyle.Fixed3D
  26.                 Me.Controls.Add(tb(t))
  27.  
  28.                 n += 1
  29.                 t += 1
  30.                 r += 24
  31.  
  32.             Next i
  33.  
  34.         End If
  35.  
  36.     End Sub
Mar 1 '13 #1
1 1692
starrj
2 New Member
I don't see the Quantity() array in your code. Where is the code that moves the value the user enters, in one of the textboxes, into an array?

If I understand your goal correctly, however, what you would need is an array of event handlers (ie TextBox1_TextChanged) matching your array of textboxes - then when the TextChanged event fires on one of them, the handler gets the value and puts it into the Quantity() array. This problem goes away when you use Classes and property viewers to manage the input/storage of information. For your example, you might write a class called "Product" that has the ProductName and Quantity properties, a textbox (withevents), a handler for the text_changed event, and methods for positioning/formatting the textbox and doing something useful with the information. In your form, you would have an array of type Product (or better, a List(of Product)) of instances of that class.
Mar 1 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
11382
by: Punky | last post by:
Hi all, I've created a workbook to play a game with my friends. Each time I insert results a new worksheet should be created (which happens) and then this worksheet should be activated. I'm fairly...
3
5276
by: Forconi Boris via .NET 247 | last post by:
Hi, I'm working on a project in witch I have to list data(products that can be selected with a certain quantity) from anXML document, with key words entered by the user. A Table isdynamically created...
1
3108
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
5
1118
by: SalamElias | last post by:
Hi, I have an aspx page with some asp:textboxes. In Page_load, I can populate the textboxes, I have a button on the page, clicking the button generates the btton_click event. My proble is I am not...
0
1760
by: mollyf | last post by:
I have multiple user controls on a form. I have a save button on each control so the users can save as they go and on the parent form, I have another button which will save/update everything...
1
1370
by: drakuu | last post by:
All, I created dynamically part of a table and its components such as text boxes etc... As you can see in the example below I created txtAddress textbox... Everything works perfectly until the...
3
29663
by: Arv Carsen | last post by:
Im a beginner with C#, but as I try to access a textbox from a thread I get the error message : "An unhandled exception of type 'System.InvalidOperationException' occurred in...
0
1294
by: Rolf | last post by:
I create several textboxes in code on the fly, using the same function. I attach a validating event in that function that calls a validating routine.. but somehow on some textboxes the validating...
2
1062
by: Mike | last post by:
Hello! I'm pretty novice in .NET and having a problem to get values from my textboxes which I have created dynamicly in my aspx.cs-file. (I'm using Visual Studio 2005). I create them like...
4
1476
by: imranabdulaziz | last post by:
Dear All, I am using asp.net2.0, C#, sql2005 using Visual studio 2005 Let Me explain the scenario I have checkboxlist containg 15 field. Based on no of checked field . I created...
0
7237
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5659
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.