Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Changing the value of text box at run time in .net 2.0 windows application

Changing the value of text box at run time in .net 2.0 windows application

Scheduled Pinned Locked Moved C#
csharphelpquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tauras81
    wrote on last edited by
    #1

    Hi, I want to change the value of text box at run time in windows application with c#.net 2005. But,I am getting the error Cross-thread operation not valid.Can anybody tell what is the reason

    D G 2 Replies Last reply
    0
    • T tauras81

      Hi, I want to change the value of text box at run time in windows application with c#.net 2005. But,I am getting the error Cross-thread operation not valid.Can anybody tell what is the reason

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      It appears that the code that's trying to alter the textBox is running on a seperate thread. What object is trying to alter it?

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Expect everything to be hard and then enjoy the things that come easy. (code-frog)

      T 1 Reply Last reply
      0
      • D DaveyM69

        It appears that the code that's trying to alter the textBox is running on a seperate thread. What object is trying to alter it?

        Dave
        BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
        Expect everything to be hard and then enjoy the things that come easy. (code-frog)

        T Offline
        T Offline
        tauras81
        wrote on last edited by
        #3

        I just want to enter the value at runtime which is coming from the serial port donot have any idea about any other object

        D F 2 Replies Last reply
        0
        • T tauras81

          Hi, I want to change the value of text box at run time in windows application with c#.net 2005. But,I am getting the error Cross-thread operation not valid.Can anybody tell what is the reason

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          This article can help you: Beginners Guide To Threading In .NET Part 5 of n[^]

          Giorgi Dalakishvili #region signature my articles #endregion

          1 Reply Last reply
          0
          • T tauras81

            I just want to enter the value at runtime which is coming from the serial port donot have any idea about any other object

            D Offline
            D Offline
            DaveyM69
            wrote on last edited by
            #5

            show these portions of your code 1. how you create your serial port reader 2. where you get the text from the serial port and attempt to assign to the textbox's Text property.

            Dave
            BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
            Expect everything to be hard and then enjoy the things that come easy. (code-frog)

            T 1 Reply Last reply
            0
            • D DaveyM69

              show these portions of your code 1. how you create your serial port reader 2. where you get the text from the serial port and attempt to assign to the textbox's Text property.

              Dave
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
              Expect everything to be hard and then enjoy the things that come easy. (code-frog)

              T Offline
              T Offline
              tauras81
              wrote on last edited by
              #6

              Serial Port Declaration : private SerialPort comport = new SerialPort(); reponse from com port : string response = comport.ReadExisting() Changing the value : textbox1.text = response.Substring(0, 1)

              D 1 Reply Last reply
              0
              • T tauras81

                Serial Port Declaration : private SerialPort comport = new SerialPort(); reponse from com port : string response = comport.ReadExisting() Changing the value : textbox1.text = response.Substring(0, 1)

                D Offline
                D Offline
                DaveyM69
                wrote on last edited by
                #7

                There's nothing using threading in the code you've posted. I assume you're using a thread to read the port, is your serial port declaration in there? BTW, there's a simple example on MSDN[^] - it might be worth comparing to your code.

                Dave
                BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
                Expect everything to be hard and then enjoy the things that come easy. (code-frog)

                1 Reply Last reply
                0
                • T tauras81

                  I just want to enter the value at runtime which is coming from the serial port donot have any idea about any other object

                  F Offline
                  F Offline
                  Frank Horn
                  wrote on last edited by
                  #8

                  I guess you're setting the text from within the comport_DataReceived event handler, which the SerialProt object calls from another thread. Either you read up on threading, or you don't use the event but put a timer onto your form (or control) and poll the com port from the timer's Tick event.

                  T 1 Reply Last reply
                  0
                  • F Frank Horn

                    I guess you're setting the text from within the comport_DataReceived event handler, which the SerialProt object calls from another thread. Either you read up on threading, or you don't use the event but put a timer onto your form (or control) and poll the com port from the timer's Tick event.

                    T Offline
                    T Offline
                    tauras81
                    wrote on last edited by
                    #9

                    Thanks,I had get the solution for my problem I had removed the comport_DataReceived from the event handler and now I am doing it with Timer now i am able to change the text box value at run time. Thanks again

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups