gpt4 book ai didi

c# - 如何在 Form2 中添加项目 - 并在 Form1 的 ListView 中查看下摆?

转载 作者:太空宇宙 更新时间:2023-11-03 14:32:25 28 4
gpt4 key购买 nike

我有 2 种形式,在形式 2 中,当我按下此按钮时,我有添加 FnameLname 项目的按钮。我想在 Form1 中的 ListView 中查看那些项目

提前致谢

最佳答案

这听起来像是您需要一个负责使用相同数据填充和维护两个表单的表示器类的情况。然后你可以从你的表单中公开按钮点击事件,并连接你的演示者来处理它。从这里您可以选择以任何方式更新您想要的任何形式。

例如:

public class MyForm1 : Form, IMyForm1
{
... // Bunch of other stuff
public event<EventHandler> onButtonClick;
}

public class MyPresenter
{
public static void Main()
{
... // Other stuff
myForm1.onButtonClick += new EventHandler<EventArgs>(ButtonHandler);
}

private void ButtonHandler(object sender, EventArgs e)
{
// Add item to form1
...
// Add item to form2. Eg:
form2.AddListItem(...);
}
}

拥有演示者的想法是,您拥有与这些表单相关的逻辑的集中位置,因此表单可以尽可能精简,而且它们甚至不必相互了解。

希望对您有所帮助。如果我错过了要点或需要澄清我所说的任何内容,请告诉我。

关于c# - 如何在 Form2 中添加项目 - 并在 Form1 的 ListView 中查看下摆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2305744/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com