CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2009
    Posts
    2

    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)
    {





    }

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    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.

  3. #3
    Join Date
    Aug 2009
    Posts
    2

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured