Button click event - displaying integer value in textbox
So I've seen several questions about this but the answers don't seem to clue me in or directly apply to what I'm trying to achieve for an application. In short, I have a button, and when it is clicked, I want a value (integer) to be displayed in a textbox. However, I get the implicit conversion error saying it can not convert an integer to a string and vice versa.
Can anyone clue me in on how I need to code it to make it work? Thanks!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test_Application
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
}
Re: Button click event - displaying integer value in textbox
Code:
private void button1_Click(object sender, EventArgs e)
{
int someInt = 123;
textBox1.Text = someInt.ToString();
int outTextbox = int.Parse(textBox1.Text); // or Convert.ToInt32(textBox1.Text)
}
I also would recommend some studying about the C# basics, because that's what this is.
Re: Button click event - displaying integer value in textbox
THANK YOU! THANK YOU! THANK YOU!
I'm coming off of VB, so yes, you're right. I need to brush up on the basics and I was surprised this wasn't included in the newbie tutorial that has taught me so much already.
By the way, code worked great!
(Probably not a surprise to you)