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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Re: How to update form control from an embedded form

Re: How to update form control from an embedded form

Scheduled Pinned Locked Moved Visual Basic
hardwaredebugginghelptutorialquestion
3 Posts 2 Posters 1 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.
  • S Offline
    S Offline
    sohaib_a
    wrote on last edited by
    #1

    hello this thread is a little old...sorry had to revive it..as i haven't yet found a solution... the name if the thread is 'How to update form control from an embedded form' I have two forms,one is added as a control to another an I need to update a listbox in parent from the child form. This code is in the parent form,I have added this in the form load event of the parent form Dim obj1 As New childform AddHandler obj1.addtolist, AddressOf addtolistbox and this is sub that is subscribed to the event.. Private Sub addtolistbox(ByVal str As String) ListBox1.Items.Add(str) End Sub In the child form.... Public Event addtolist(ByVal s As String) and in the sub where I want to add to listbox in parent form, RaiseEvent addtolist(ds1.Tables(0).Rows(0)("Reader_location").ToString & " Connected ") I have tried this and it doesnt work,the debugger just goes to next line.Can't understand why. The code of the parent form has some BGW threads.Infact the child form is invoked from the BGW.Is this a problem?

    D 1 Reply Last reply
    0
    • S sohaib_a

      hello this thread is a little old...sorry had to revive it..as i haven't yet found a solution... the name if the thread is 'How to update form control from an embedded form' I have two forms,one is added as a control to another an I need to update a listbox in parent from the child form. This code is in the parent form,I have added this in the form load event of the parent form Dim obj1 As New childform AddHandler obj1.addtolist, AddressOf addtolistbox and this is sub that is subscribed to the event.. Private Sub addtolistbox(ByVal str As String) ListBox1.Items.Add(str) End Sub In the child form.... Public Event addtolist(ByVal s As String) and in the sub where I want to add to listbox in parent form, RaiseEvent addtolist(ds1.Tables(0).Rows(0)("Reader_location").ToString & " Connected ") I have tried this and it doesnt work,the debugger just goes to next line.Can't understand why. The code of the parent form has some BGW threads.Infact the child form is invoked from the BGW.Is this a problem?

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Don't start a new thread. Keep responding to the same thread so people can see what'sbeen going on.

      Sohaib_A wrote:

      The code of the parent form has some BGW threads.Infact the child form is invoked from the BGW.Is this a problem?

      Great! NOW you mention the child form is on a background thread. First, this is a bad idea. ALL GUI objects (forms included) should only be created on the UI thread. Any work that needs to be done can go on a seperate thread. Since the BGW is NOW the case, what you've been told is not going to work. You cannot modify controls created on the UI from another thread. You can pretty much scrap half of the things you were told and start looking into the ReportProgress method of the BGW. This is pretty much going to be the easiest method of getting periodically generated data out of the code that the BGW is running. You're looking for this[^] version of the method.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Don't start a new thread. Keep responding to the same thread so people can see what'sbeen going on.

        Sohaib_A wrote:

        The code of the parent form has some BGW threads.Infact the child form is invoked from the BGW.Is this a problem?

        Great! NOW you mention the child form is on a background thread. First, this is a bad idea. ALL GUI objects (forms included) should only be created on the UI thread. Any work that needs to be done can go on a seperate thread. Since the BGW is NOW the case, what you've been told is not going to work. You cannot modify controls created on the UI from another thread. You can pretty much scrap half of the things you were told and start looking into the ReportProgress method of the BGW. This is pretty much going to be the easiest method of getting periodically generated data out of the code that the BGW is running. You're looking for this[^] version of the method.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        S Offline
        S Offline
        sohaib_a
        wrote on last edited by
        #3

        Ok..so I got it to work.Had to get rid of the BGW.You were right,they were a bad idea.But i wonder why I wasn't getting any cross-threading errors. Actually what i was trying to do is,I have a snippet code in which there are several API calls for a certain hardware device and the data that i get from this device has to be dispayed on a form and also manipulated in a database. I want to run several instances of this code at the same time as I have more than device running at the same time performing the same operation.Also the devices will perform this operation at specific intervals. Currently I am doing this using timers for the operation interval and lists for the multiple forms.All these forms are added as control to a parent form. I want to try to get this to work using threading,i:e; each 'device' or instance would be running in its own thread.And all the threads would be running and instance of the code in parallel. I tried using BGW lists to create forms and run the code,but there were many complications one of which you know. I don't know much about threading as i haven't done it before,all I know is stuff I've read online. My questions are 1.As threading is known to improve performance and response of an application,will it do the same in this case or just make it more complicated and slower? 2.If threading is the way to go,will there be issues of thread synchronization and can all these threads run in parallel?

        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