Welcome to Dream.In.Code
Become a C# Expert!

Join 150,416 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,021 people online right now. Registration is fast and FREE... Join Now!




Populating Form Control with String

 
Reply to this topicStart new topic

Populating Form Control with String

SpudNik867
18 Mar, 2008 - 02:34 PM
Post #1

New D.I.C Head
*

Joined: 18 Mar, 2008
Posts: 4

Hey y'all..


So Im struggling with getting going with some .NET concepts. I have written a small POP3 class that appears to work because I can return values from it using message boxes. I just need to know how to populate form controls such as text boxes. So looking at my example, how would I populate "textBox1" on "Form1" with the contents of the varible numMessages?

Just trying to get my feet wet.. any assistance would be rad.

Thanks

CODE
        try
    {
        Pop3 obj = new Pop3();

        int numMessages = 0;
        string newMess;

        obj.Connect("servername", "username", "password");
        ArrayList list = obj.List();
        foreach (Pop3Message msg in list )
        {
            Pop3Message msg2 = obj.Retrieve(msg);

            numMessages = numMessages + 1;
            
        }


This post has been edited by SpudNik867: 18 Mar, 2008 - 02:51 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Populating Form Control With String
18 Mar, 2008 - 02:39 PM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Take a look at the modification I made to your code


csharp

try
{
Pop3 obj = new Pop3();

int numMessages = 0;
string newMess;

obj.Connect("webmail.mobiledataforce.com", "nmartin", "bingogo86&");
ArrayList list = obj.List();
foreach (Pop3Message msg in list )
{
Pop3Message msg2 = obj.Retrieve(msg);
//here we can do += 1 to increment the counter.
//No longer need to use something = something + 1
numMessages += 1

}
//we will set the Text property of our TextBox to the value
//returned from numMessages. You need to use the ToString()
//method to convert it to text before you can display it
textBox1.text = numMessages.ToString();



Hope that helps smile.gif
User is offlineProfile CardPM
+Quote Post

SpudNik867
RE: Populating Form Control With String
18 Mar, 2008 - 02:50 PM
Post #3

New D.I.C Head
*

Joined: 18 Mar, 2008
Posts: 4

Ya.. I thought it was that easy but I get an error when trying to compile.

'The name "textBox1" does not exist in the current context.'

So how do I manipulate form controls from like the Main() for example?

Thanks for the reply









QUOTE(PsychoCoder @ 18 Mar, 2008 - 03:39 PM) *

Take a look at the modification I made to your code


csharp

try
{
Pop3 obj = new Pop3();

int numMessages = 0;
string newMess;

obj.Connect("servername", "username", "password");
ArrayList list = obj.List();
foreach (Pop3Message msg in list )
{
Pop3Message msg2 = obj.Retrieve(msg);
//here we can do += 1 to increment the counter.
//No longer need to use something = something + 1
numMessages += 1

}
//we will set the Text property of our TextBox to the value
//returned from numMessages. You need to use the ToString()
//method to convert it to text before you can display it
textBox1.text = numMessages.ToString();



Hope that helps smile.gif


This post has been edited by SpudNik867: 18 Mar, 2008 - 02:53 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Populating Form Control With String
18 Mar, 2008 - 02:58 PM
Post #4

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
You're getting that error because you dont have a TextBox named "textBox1". You can access any control on your form from any method that it contains. Double check the name of your TextBox. Also, this code is in the Form's code corrent (as opposed to being in a separate class file)
User is offlineProfile CardPM
+Quote Post

SpudNik867
RE: Populating Form Control With String
18 Mar, 2008 - 03:07 PM
Post #5

New D.I.C Head
*

Joined: 18 Mar, 2008
Posts: 4

That's odd.. I'm fairly certain it is called 'textBox1'. So if I double click the control from the form I am taking to the code that was generated:

CODE
private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
            
        }

The property window shows that name as textBox1 as well??

Bazarre
User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: Populating Form Control With String
18 Mar, 2008 - 03:10 PM
Post #6

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 9,483



Thanked: 161 times
Dream Kudos: 9075
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Theres a typo in my example, C# is case sensitive and text isnt correct, it should be Text like


csharp

textBox1.Text = numMessages.ToString();

User is offlineProfile CardPM
+Quote Post

SpudNik867
RE: Populating Form Control With String
18 Mar, 2008 - 03:24 PM
Post #7

New D.I.C Head
*

Joined: 18 Mar, 2008
Posts: 4

I noticed... but the name of the control is "textBox1". That is in the correct case.


I really don't think the problem is the name of the control. Did you see the auto generated code? So this is weird.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 08:06PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month