473,831 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Moving data to & from form/class


I am still struggling with a pattern that can be used to move data
from a class to a related form, and from the class method results to
text boxes, listboxes, etc on the form. I usually get it working by
adding enough contructors and instances (but I'm sure that I don't
always point at the form or class instant that I am expecting).

This is frustrating because it should be so simple. BTW, I tried
putting:

Tester t = new Tester(); on the form1 load event, and
Form1 f = new Form1(); at the top of the class the class.

This resulted in an infinite loop. I hope that this code describes my
issue, but if it dowsn't please let me know what you want to see.
Thanks very much for taking some time with this.
tester.cs:

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Windows. Forms;

namespace Test
{
public class Tester
{

public int total;

public void Foo()
{
string b = "bar"
}

public void Bar() {
{
int i = 0;

int j = 0;
int k = 0;
int m = 0;
int n = 0;
int p = 0;

for (i=0;i<entries< i++)
int sum1 = j + k;
sum2 = m+n+p;
total = sum1 + sum2;
}

Here is the form1.cs

using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Windows. Forms;

namespace Test

public partial class Form1 : Form
{
public Tester t = new Tester();
public Form1()
{
InitializeCompo nent();
}

private void buttonBegin_Cli ck(object sender, EventArgs e)
{
listBox1.Items. Add(t.b);
}

private void PopulateListBox Fields (string message)
{
listBox1.Items. Add(t.total);
}
}
}


Dec 16 '07 #1
1 1211
On Sat, 15 Dec 2007 17:43:27 -0800, Blip <bl**@krumpli.c omwrote:
I am still struggling with a pattern that can be used to move data
from a class to a related form, and from the class method results to
text boxes, listboxes, etc on the form.
The exact pattern will depend on your specific needs in a particular
situation. However, the basic idea is always the same: instantiate the
objects as is appropriate for the lifetime of the object, not specifically
for the purpose of exposing one object to another. Then, make a different
(but possibly related) design choice regarding exposing one object to
another.

Usually this latter step involves passing a reference for the instance of
one class to the instance of another. Occasionally, some other mechanism
will be used, such as a singleton or some sort of static variable or
collection.

What's correct just depends on your specific situation.
I usually get it working by
adding enough contructors and instances (but I'm sure that I don't
always point at the form or class instant that I am expecting).
IMHO, you should go about it in a more directed way. A sure path to
terrible, buggy, difficult-to-maintain code is to just add stuff until it
works. You should get out of that habit asap.
This is frustrating because it should be so simple. BTW, I tried
putting:

Tester t = new Tester(); on the form1 load event, and
Form1 f = new Form1(); at the top of the class the class.

This resulted in an infinite loop.
Yes, of course it would. Fortunately in that case, "adding enough
constructors and instances" just blew up. But it's a good demonstration
of why a more directed approach is better.
I hope that this code describes my
issue, but if it dowsn't please let me know what you want to see.
Well, the one thing I don't understand in the code you posted is what
exactly you're trying to show. I would say that the biggest issue is that
your Form1 class tries to reference a non-existent member "b" of the
Tester class. You've got a "b" in the Tester class, but it's a local
variable. It would have to be a public field or property for Form1 to get
at it.

Other than that problem I would think that the code would work fine as
written (not counting missing braces and whatnot, which I'll assume is
just a mistake that happened when posting the code).

Maybe you can be more specific about what in the code you posted isn't
working, and how you'd like it to work.

Pete
Dec 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4455
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most part, the scripts were created with http://phpcodegenie.sourceforge.net/
2
2512
by: PMB | last post by:
Thank you in advance for any and all assistance. I'm trying to input data from strings to a memo field. I would like to know how to check first to see if there is text there currently and if so move to the end and input the new text. Also, would like to know if I can change the justification on each line of text as it's entered. i.e. Company Name, address, city state and zip would be centered and all the
0
3734
by: TheCoder | last post by:
I am making a D-base with web conectivity for my class project. I have everything working but the subit button sends the data to the correct fields but afterwards it wants to reproduce new blank text boxes how do I stop this and how would I code it to redirect to a thank you page. All with out the help of a web server this has to br ran from the desktop and with in IE with a local directory. Pleas help I am stuck. here is the code! ...
21
3515
by: MLH | last post by:
A97 procedure to open http://www.arch.com/message/ enter an 800 number, press "Continue", enter a text msg string from a memo field and press "Send" This is a calendaring and appointment A97 database for an attorney's office. I'm sure it must be do-able. I know better than to mention the term "S__dK__ys" in conjunction with this topic. I've read enough in here to know that is extremely unreliable. Am sorry even that I have to use IE...
5
4333
by: Matthew Hood | last post by:
Here's a interesting question for the guru's out there. I've created a VB.NET class library with a couple of forms that I have successfully got to work from within MS Access using COM interop and VBA. (Working, meaning it hasn't crashed on me yet... ;-). I Would anybody know how to take this VB.NET Winform (using it's handle, subclassing, or other means) and set it's parent to be the Access MDI client area so that it will behave as if...
2
9381
by: Diogo Alves - Software Developer | last post by:
Greetings I would like to knowhow can I put a sliding panel... I've done this: if (panel1.Width < 300) { while (panel1.Width < 300) { panel1.Width = panel1.Width + 40;
23
14529
by: Bjorn | last post by:
Hi. Every time i post data in a form the contents are being checked for validity. When i click the back-button, all data is gone and i have to retype it. It's obvious that only a few or none of the visitors will retype it all so i'm asking: "how to preserve POST-data when clicking the back-button?" i've already tried to print post data as a value in a HTML tag but
1
1803
by: Anthony Smith | last post by:
Let's say that I have some data like what is listed below. I simply want to get all of he text that is between the html tags. How would I do that with regular expressions or any kind of code. Also, I want to learn how to use regular expressions. What is a good site to get me started with php? <tr><td class="yfnc_h" nowrap="nowrap"><b><a href="/q/op? s=GME&amp;k=30.000000">30.00</a></b></td><td class="yfnc_h"><a href="/
1
3873
colinod
by: colinod | last post by:
Hi everyone i am trying to make a page that goes to the next recorset when i click on a button so the page only shows one record at a time, this is for updating so i need to be able to go to the next recodset from the page that updates the database also. the code for the page that i have which lists all the records is as follows <%@LANGUAGE=VBSCRIPT%> <%voiceid=Request.Querystring("id")%> <% Response.Expires=0
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10777
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10534
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9317
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5619
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5780
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3076
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.