updating the main form from a 2nd form

Collapse
X
 
  • Time
  • Show
Clear All
new posts

  • wimpos
    replied
    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.

    Leave a comment:


  • Semajthewise
    replied
    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

    Leave a comment:


  • Nunu
    replied
    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

    Leave a comment:


  • Semajthewise
    replied
    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.

    Leave a comment:


  • Nunu
    started a topic updating the main form from a 2nd form

    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.
Working...