-
January 16th, 2009, 04:32 PM
#1
int to a textbox
on a windows application I have a txttable that I am trying to write an int in.
It works fine when i send a string to it, it prints it by doing the following
Code:
txtTable.Text = "Hello dealer";
but when i try to send an int variable to it like so
[code]
int x=10;
txtTable.text=x;
[code]
i get the following error
Cannot implicitly convert type 'int' to 'string'
how then can i put this int out to the text box?
Thanks
-
January 16th, 2009, 04:35 PM
#2
Re: int to a textbox
Just a thought: The ToString method of the Int32 structure perhaps?!
msdn
sheesh!
It's not a bug, it's a feature!
-
January 16th, 2009, 04:45 PM
#3
Re: int to a textbox
well thanks
the sarcasm is not needed, I am not an idiot
just new to C# and asking a question, and i did not know about the msdn site
if you are too good for such an answer... then just don't answer
Sheesh
-
January 16th, 2009, 04:45 PM
#4
Re: int to a textbox
Check out the beginner's tutorials.
Foamy is snarky because you have obviously not tried to fix it yourself. It is one of the most basic concepts in programming; data types.
-
January 16th, 2009, 04:52 PM
#5
Re: int to a textbox
like I said if you don't want to answer a basic question then don't answer it. It is a message board, anyone can answer who wants to. I did not call him up or send a personal email.
And I did try to fix it my self but got stuck, but I did not know how the txttable works thats why I ask for help.
-
January 16th, 2009, 05:00 PM
#6
Re: int to a textbox
It's ok, I didn't mean to sound rude, it's just that it is *very* basic. If you look at the textbox's "Text" property, you can see that it is of type string. So, that means that you cannot assign an integer to it. A simple search for "Convert integer to string" would have pulled up thousands of results.
-
January 16th, 2009, 10:09 PM
#7
Re: int to a textbox
Use the ToString() method in order to convert the int variable into string, i.e.:
Code:
int num = 10;
myTextBox.Text = num.ToString();
//myTextBoxText is no containing the value "10" (and NOT 10, which is numerical)
-
January 16th, 2009, 10:41 PM
#8
Re: int to a textbox
Originally Posted by maitopoika
well thanks
the sarcasm is not needed, I am not an idiot
just new to C# and asking a question, and i did not know about the msdn site
if you are too good for such an answer... then just don't answer
Sheesh
Not knowing about the MSDN site means you did NOT read the documentation that comes with the product.
So that would either indicate that you already believe you know Everything about the product or ...... well' lets just say your post has an inaccuracy....
I am sure this post has added you to the ignore list of many many people.
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
January 18th, 2009, 12:19 PM
#9
Re: int to a textbox
Looking to your former posts i have seen you obviously changed from C++ to C# now.So you have to know: C# is different to C++ in a lot of things. Therefor I would recommand you ( even if you are maybe an expierenced programmer in another language ) take a beginners book like 'MS Visual C# 2005 Step by Step' ( Maybe in between its Visual C#2008 step by step , I dont know ) It will not need for long to get all this basics in and after that it will be much easier for you to use C#.
In comparing C# to older languages like VB 6.0 where it was no problem to do
Code:
Dim x as Integer
Textbox1.Text = X
This is not possible in C#. C# is very exact in types and as you see and will learn to love,the intellisense is very pregnant and exact. If your intellisense doesn't show you the variable you already have defined when typing the first few letters of it, something is wrong like you may have defined the variable within a loop or an ' if ' condition and now trying to use it outside of it, or something others which isn't allowed in C# and was no problem in C++ or VB.
Trying to compile you will get the errormessages, but you can see problems very often before even compiling by having an eye on the intellisense.
This should only be a hint for some very new C# users.
Jonny Poet
To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
If anyone felt he has got help, show it in rating the post.
Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
My latest articles :
Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|