使用 3 个表单和一个 ListView

Working with 3 Forms and a ListView

我有3个表格。让我们称它们为 Main、UserInput 和 ListViewForm。

我使用 UserInput 中的数据将数据添加到 Main 上的列表。 List 用于管理显示添加的总项目数的 TextBox。该列表需要与 ListViewForm 上的 ListView 具有相同的内容。因此,如果 TextBox 显示 5,则 ListView 需要具有这 5 个项目。我知道如何将项目直接添加到具有 2 种形式的 ListView,但在这种情况下,我使用的是 3。我认为需要做的是在我的添加按钮事件中同时将项目添加到 List 和 ListView在输入表单中。

在 ListViewForm 上,如果我是 using UserInput ui = sender as UserInput,我需要能够触发将 运行 ListView 中的方法的事件。该事件是我在 UserInput 中的添加按钮,但我无权访问该表单以指示 EventHandler 订阅 ListViewForm。

这是 ListViewForm 上的方法

public void addToListView(object sender, EventArgs e)
        {
            //Method to Add to ListView
            userInputForm listItems = sender as userInputForm;
            //listItems.ItemNumChange += addToListView;
            Person c = listItems.dataInfo;

            ListViewItem lfi = new ListViewItem();
            lfi.Text = listItems.dataInfo.Name;
            lfi.Tag = c; 
            listView1.Items.Add(lfi);
        }

向您的表单添加事件处理程序。