954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need some help sending data

Hello,

Hey guys, love the forums here, very nice.

I am having a bit of coding problem with an assignment from college. (I read the announement no worries I am not looking for you to do it for me ^_^)

Anyway, I have a form, which I am not done coding yet, that needs to send all the data that is entered on the form to an object. This happens when the user clicks thr "add" button. I need to know, how can I get my object to recognize m form and accept data from it?

Here is what I am thinking migh be the code to do so (in the object)

public int STR
{
get
{
return str;
}
set
{
str = strBox.Text;
}

}

Am I close to the right idea? Also, could someone post a possible syntax for this?

I can post my existing code, but I do not think it will bw neccessary.

CollegeKid101
Newbie Poster
3 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

Well. A form is an object like any other object in c#, and you have many options. However, lets assume you're going to make a phonelist holder of your friends. On the main form you want a list maybe of names, so you can quickly find the person you're after. The second form holds more details, such as address, phone number, date of birth, stuff like that.

If you make a class to hold all that data, you can pass it as a single contained lump much like handing a cup of coffee over, you dont ask someone if they want one, and then hand over 1 cup a handful of hot water, ground stuff, maybe a dribble of milk and some sugar do you?

Then what you can do is setup a function to call in your second "details" form, where you send it the class as parameter, which can then populate the details form, and everyones happy.

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

That makes sense, but the assignment calls for a very specific action, and my instructor is, how we say....fickle.

AT any rate, is there a way to pass al this information like the cup of coffee from just one form to one class? If so, would it be possible to show some comparable code snippets? Thank you for all the help!

CollegeKid101
Newbie Poster
3 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

Well..

void DataInit(myclass data)
{
if (data!=null)
{
  txName.Text=Data.Name;
  txtAge.Text=Data.Age;
  txtAddress.Text=Data.Address;
}
else
{
 txName.Clear();
txAge.Clear();
txAddress.Clear();
}

}


There are a ton of alternatives.

For example, to be honest, you could make the form part of the data class, as its going to display it, you could make the data a property on the form and when it changes it knows to update the form..

A fickle instructor is a *good* thing.

Now, the way Ive suggested is semi OK, but obviously its not going to return the data to your form. If you want that you could of course pass by reference.

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 
public int STR
        {
            get
            {
                return str;
            }
            set
            {
                 str = strBox.Text;
            }
           
        }


This looks like a property to me, but your syntax is not correct
do it this way:

private string str;

        public string STR
        {
            get
            {
                return str;
            }
            set
            {
                 str = value;            }
           
        }


To get the string : Myclass.str
To set the string : Myclass.str = strBox.Text;

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

See also this code snippet by dickersonka : http://www.daniweb.com/code/showsnippet.php?codeid=1008

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

thanks for the reference ddanbe :-)
just so happened to coincide with me posting

dickersonka
Veteran Poster
1,175 posts since Aug 2008
Reputation Points: 130
Solved Threads: 143
 

Lots of information to go over here!

I think my issue is I am over thinking this. The problem I had was I was trying to get my object to gather information from my form, when my form should have been sending the data to the object. I think I might have it here, thanks to your guys help! Thank you so very much!

CollegeKid101
Newbie Poster
3 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You