在C#中显示同一表单的多个实例中的值 [英] Displaying values in multiple instance of the same form in C#

查看:71
本文介绍了在C#中显示同一表单的多个实例中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的C#应用​​程序中有一个winform。这个winform有一些控件,一个发送按钮和列表视图来显示值。我有内部逻辑发送请求,检索到的值显示在列表视图中。因此,如果我打开表单,请发送请求,并将值列入表单的列表视图中。此表格保持打开状态。当窗体的另一个实例打开时,将发送请求,检索值,但值将显示在窗体的第一个实例的列表视图中。我该如何解决这个问题?

I have a winform in my C# application. This winform has some controls, a send button and list view to display values. I have internal logic which sends a request and the retrieved values are displayed in the list view. So If I open the form, send request and the values are enlisted in the listview of the form. This form is left open. When another instance of the form is open, request is sent, the values are retrieved but the values are getting displayed in the listview of the first instance of the form. How can I fix this?

推荐答案

取决于您的代码,我们看不到:但在某处,您正在将信息传输到错误的实例。



当您创建表单的新实例时,您需要使用该新实例来填写信息。猜测 - 这就是没有代码的情况 - 您使用静态变量来保存信息,或者您通过变量而不是使用新变量来引用单个实例。



从检索值的代码开始:它在哪里? 父母形式?还是孩子形式?你如何访问该代码中的表单?

创建新表单时你会怎么做?是这样的:

Depends on your code, which we can't see: but somewhere, you are transferring information to the wrong instance.

When you create a new instance of a form, you need to use that new instance to "fill in" the information. At a guess - and that's all it can be without your code - you are using a static variable to hold information, or you are referring to a single instance via a variable rather than using the "new" one.

Start with the code that retrieves the values: where is it? "Parent" form? or "Child" form? How do you access the form in that code?
What do you do when you create a new form? is it along the lines of:
MyNewForm f = new MyNewForm();
FillInFormInformation();
f.Show();

如果是这样,那么你可能需要在FillInFormInformation中添加一个参数,允许你传递f



但我们不能说,不是从这里。所以你需要开始寻找!

If so, then you probably need to add a parameter to FillInFormInformation that allows you to pass "f"

But we can't tell, not from here. So you need to start looking!


这篇关于在C#中显示同一表单的多个实例中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆