Ronald Grossett

Ronald Grossett

  • NA
  • 12
  • 894

Help with coding a event handler

Jun 7 2019 4:05 AM

I know this topic has been covered several times however its still unclear to me.

I am creating Windows Forms Application believe to be called a singleton program design.
This is using a main form with differents options for the user to select.
These options in turn all have their corresponding forms with unique functions attached.
When the main form executes and the user select an option, the option form is then hidden
away from the user (as oppose to close) until its selected again. Note.. ITS NOT CLOSED.

I have a form with a richtext box and after checking contents validity, I want to send
that data to another form thats got a listview box... basically updating the listview box
on the other form.
 
All of the examples I have seen creates new instances of forms which is not ideal in my case
 
My question is:- how do I get data/information from one form to another form.
.
I tried creating a custom made event handler but have hit a buffer/brickwall
 
This is what I have got so far....
 
    public delegate void EventDelegate(Object sender, EventArgs e);
    public event EventDelegate MessageForListView;
 
   if (status == 0){
       value = value.ToLower();
       using (StreamWriter sw = File.AppendText(path)){
       sw.WriteLine(value + " " + datestamp);
       MessageBox.Show(value.ToString() + " is now registered....... ");
       //message event required here to pass back value and datestamp to the form holding the ListViewBox
        MessageForListViewEvent += NewDriverForm_MessageForListViewEvent;
      ReSetInput();
     }
   }
 
   private void NewDriverForm_MessageForListViewEvent(object sender, EventArgs e){
        // how do I write the data into the ListViewBox or call the reload procedure again.
   }
 
thanks in advance

Answers (4)