473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Textbox array in Class

33
Hi:
I wrote this code:
Expand|Select|Wrap|Line Numbers
  1. Class Manager
  2. private TextBox[] aTextbox = new TextBox[10];
  3. private string[] sD = new string[10];
  4. public SerialManager()
  5.         {
  6.             for (int k = 0; k < aTextbox.Length; k++)
  7.             {
  8.                 aTextbox[k] = new TextBox();
  9.             }
  10. }
  11.          void comPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
  12.         {
  13.             string msg= comPort.ReadTo("\r");
  14.             TabulatedData(msg);
  15.         }
  16.         public void TabulatedData(string msg)
  17.         {
  18.             for(int j=0;j<7;++j)
  19.             {
  20.                 sD[j] = msg.Substring(7 + j * 4, 4);
  21.                 aTextbox[j].Text = sD[j];
  22.  
  23.             }
  24.  
  25.         }
  26.  
The above code is only partial. I can get the value in sD[ j ], but I'm not able to Display with window Form.
If I have a Form with Textboxes , How can I Display Values From the Class ?

Thanks
Jul 14 '08 #1
9 1778
Plater
7,872 Expert 4TB
You would need to add the textboxes to your Form.Controls collection.
Jul 14 '08 #2
Jetean
33
You would need to add the textboxes to your Form.Controls collection.

How to add ? Can you show me?

Thanks
Jul 15 '08 #3
Plater
7,872 Expert 4TB
myForm.Controls.Add(someTextBox)
Jul 15 '08 #4
Jetean
33
myForm.Controls.Add(someTextBox)
Ah, Ok. But I think may be I question is misunderstood. I have this problem where I created an array of Textboxes in Class file, but I would like to display the textboxes values from Class file onto Form class
just like this


Class.Atextbox=Textbox1;

But how to do it in Array

Class.Atextbox[]=Textbox [] ???

Thanks
Jul 16 '08 #5
Plater
7,872 Expert 4TB
Well your class confuses me. You store the values of the textboxes AS well as the textbox(which includes the value).
Seems a bit bloated/redundant?
Jul 16 '08 #6
Jetean
33
Well your class confuses me. You store the values of the textboxes AS well as the textbox(which includes the value).
Seems a bit bloated/redundant?
Hi Plater:
I created a class so that I can reused the code again. The class will continously update data and display value in textboxes. So At Form my code will be minimum. I only need to "map" the textboxes from the Form relatively to the Class textboxes during intial Form load.

by the way what Controls.add can do if all the textboxes are added to control, any example on the usage?
Jul 16 '08 #7
Plater
7,872 Expert 4TB
Hmm, you don;'t normally abstract the GUI out of the GUI, but I guess it could work.
You could have a function in your class like such:
Expand|Select|Wrap|Line Numbers
  1. public void AddControls(ControlCollection c)
  2. {
  3.    foreach(TextBox t in aTextbox)
  4.    {
  5.       //some design code for 't' can go here
  6.       c.Add(t);
  7.    }
  8. }
  9.  
Then you could either pass in this.Controls, or like myGroupBox.Controls and it will dump the textboxes into there.
Note: You may have to do some design code too like location/size/etc
Jul 16 '08 #8
Jetean
33
Hmm, you don;'t normally abstract the GUI out of the GUI, but I guess it could work.
You could have a function in your class like such:
Expand|Select|Wrap|Line Numbers
  1. public void AddControls(ControlCollection c)
  2. {
  3.    foreach(TextBox t in aTextbox)
  4.    {
  5.       //some design code for 't' can go here
  6.       c.Add(t);
  7.    }
  8. }
  9.  
Then you could either pass in this.Controls, or like myGroupBox.Controls and it will dump the textboxes into there.
Note: You may have to do some design code too like location/size/etc
Platter:
You are saying I add a Function at Form or the Class that I created? ControlCollection can only be found in Form but not Class.cs?

Then you could either pass in this.Controls, or like myGroupBox.Controls and it will dump the textboxes into there.

Can you elaborate more?

Thanks
Jul 17 '08 #9
Plater
7,872 Expert 4TB
I said to put it in your class, if you wanted to keep the textboxes in there.
But you could do it either way.
Jul 17 '08 #10

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

Similar topics

2
by: mcl chan | last post by:
Hello all, I'm using below code for c# app to call another app { System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc Enable.RaisingEvents=false; proc...
12
by: Peter | last post by:
I'm looking to create multiple textboxs that change to a light blue on focus. What is the most efficient way to do this? -Peter
7
by: DazedAndConfused | last post by:
Curently I manualy code keypress edits. i.e. allow only 3 digits before decimal and two digits after decimal in .NET. Is there an easy solution to mask text boxes? The MSMASK32.OCX from vb6...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
2
by: blitzztriger | last post by:
Hello!! how do i insert values into mysql , after parsing a submiting textbox?? I made the arrays, so this should be a basic insertion of them in the db, but something is missing, or in the wrong...
1
by: bethmiddy | last post by:
Hello, I am very new to programming and am currently taking a class on VB. This is probably very simple, I just don't get it. I am working on a group project where we need to have 3 columns and...
2
by: HariKutty | last post by:
Hello Every one My Use Case: I want to display the list of matching email address from the word typed in by the User. Example If the User types "a" in textbox then it shoud display ...
6
by: john | last post by:
I have the following textbox setup with Text & ToolTip Bindings as follows; I'm using Visual Studio 2008 VB: <asp:TextBox ID="txtDay1" runat="server" Text='<%# Eval("Day1") %>'...
9
mageswar005
by: mageswar005 | last post by:
Hi Guys, My array textbox validation is not working fine,my code is given below please help me immediately. function validation() { var chks =...
7
by: Angel López | last post by:
How to do this with Vb.net 2008??? myNumber=1+ Int(Rnd()*90) text(myNumber).backcolor=vbRed Tanks Angel
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.