updating the main form from a 2nd form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nunu
    New Member
    • Jan 2008
    • 2

    updating the main form from a 2nd form

    Hi there.

    this is what I have... listview on mainform named lstViewFrmMain, 1 textbox and a button on frm 2.

    My question is, how do I update the listbox when a user clicks button on the 2nd form?
    I've tried using on the main form - this,Refresh(), this,Update(), this.Invalidate () etc and its not helping.

    Any help will be tremendous.
  • Semajthewise
    New Member
    • Nov 2007
    • 38

    #2
    Originally posted by Nunu
    Hi there.

    this is what I have... listview on mainform named lstViewFrmMain, 1 textbox and a button on frm 2.

    My question is, how do I update the listbox when a user clicks button on the 2nd form?
    I've tried using on the main form - this,Refresh(), this,Update(), this.Invalidate () etc and its not helping.

    Any help will be tremendous.
    are you getting errors? is the code not doing as intended? When posting please include this type of information and anything else that might be relevent.

    But to make a suggestion on your problem. Is your listview public? if not mak it public or you cannot update it from another form.

    Comment

    • Nunu
      New Member
      • Jan 2008
      • 2

      #3
      Originally posted by Semajthewise
      are you getting errors? is the code not doing as intended? When posting please include this type of information and anything else that might be relevent.

      But to make a suggestion on your problem. Is your listview public? if not mak it public or you cannot update it from another form.
      Hi there .


      It is public and there's no errors at all. If u want I can email u my source code
      Thank you

      Comment

      • Semajthewise
        New Member
        • Nov 2007
        • 38

        #4
        Originally posted by Nunu
        Hi there .


        It is public and there's no errors at all. If u want I can email u my source code
        Thank you
        just post what you have on your button here and Myself or someone else can maybe solve your dellema

        Comment

        • wimpos
          New Member
          • Jan 2008
          • 19

          #5
          Originally posted by Nunu
          Hi there.

          this is what I have... listview on mainform named lstViewFrmMain, 1 textbox and a button on frm 2.

          My question is, how do I update the listbox when a user clicks button on the 2nd form?
          I've tried using on the main form - this,Refresh(), this,Update(), this.Invalidate () etc and its not helping.

          Any help will be tremendous.
          Hi

          you should use events.

          In your second form you declare

          Code:
           public delegate void MyUpdateEventHandler(string msg);
          public event MyUpdateEventHandler MyUpdateEvent;
          
          // in the buttonclick method you add
          if(MyUpdateEvent != null)
          {
              MyUpdateEvent(myTextBox.Text);
          }
          In your Main form you do

          Code:
           MySecondForm f = new MySecondForm();
          f.MyUpdateEventHandler += (pressing TAB TAB in visual studio will auto-generate a method)
          
          f.Show();
          more info on events: http://www.thescripts.com/forum/thread760508.html

          In that generated method you must update your mainForm. However you'll have to use delegates and Control.Invoke for threadsafety.

          Hope this helps

          Regards
          W.

          Comment

          Working...