Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The most straight forward way of doing things would be to use events. You could add an event on <code>form2</code> that would fire each time an item is added, and includes the text to be inserted (you have multiple pieces of information, so a custom data type would be appropriate). You can then add a handler method to <code>form2</code> which adds the item to its ListView. You then tie the two together in the code that is creating the two forms, and life should be good.</p> <p>So, to provide some code, First up is the data structure for the event:</p> <pre><code>public delegate void HandleItemAdded(object sender, ItemAddedEventArgs e); public struct ItemAddedEventArgs : EventArgs { public string Name; public string Email; public string Phone; public ItemAddedEventArgs(string name, string email, string phone) { Name = name; Email = email; Phone = phone; } } </code></pre> <p>Then we have the event code on <code>form2</code></p> <pre><code>public event HandleItemAdded ItemAdded; // .. some other stuff public void RaiseItemAdded(ItemAddedEventArgs e) { if(ItemAdded != null) ItemAdded(this,e); } // ... now for your AddToList public void AddToList() { RaiseItemAdded(new ItemAddedEventArgs(txtName.Text,txtEmail.Text, txtPhone.Text); } </code></pre> <p>And now we can add a handler in <code>form1</code></p> <pre><code>public void HandleItemAdded(object sender, ItemAddedEventArgs e) { ListViewItem item1 = new ListViewItem(txtName.Text); item1.SubItems.Add(txtEmail.Text); item1.SubItems.Add(txtPhone.Text); MyListView.Add(item1); } </code></pre> <p>And last but not least we need to tie them together</p> <pre><code>//...not sure what your code looks like, but we'll assume we have instances of the two forms named form1Form and form2Form form2Form.ItemAdded += form1Form.HandleItemAdded </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload