C# 在运行时,如何更新隐藏窗体上的listview控件

C# 在运行时,如何更新隐藏窗体上的listview控件,c#,winforms,C#,Winforms,我得到了一个隐藏的表单(ViewRegisterPerform),它有一个ListView。此表单是隐藏的,但我想在运行时从另一个表单(RegistrationForm)更新ListView 老实说,我不确定什么是处理这种情况的最佳方法,因此我愿意接受建议 private void UpdateListView(string value){ ViewRegisterForm.MdiParent = this; ViewRegisterForm.Show()

我得到了一个隐藏的表单(ViewRegisterPerform),它有一个ListView。此表单是隐藏的,但我想在运行时从另一个表单(RegistrationForm)更新ListView

老实说,我不确定什么是处理这种情况的最佳方法,因此我愿意接受建议

    private void UpdateListView(string value){
        ViewRegisterForm.MdiParent = this;
        ViewRegisterForm.Show();
        ViewRegisterForm.Location = new Point(10, 5);

    }

显然,这不起作用

您遇到的问题如下: 您正在尝试直接引用该类,而不将其转换为实际对象

首先创建对象,并将其设置为
表单
类型

ViewRegisterForm VRF = new ViewRegisterForm();
现在您将处理这个对象,而不是类本身

使用
VRF.publicObjectInThis表单调用它们

下面是使用您的代码的完整示例

在C#中:


私有void UpdateListView(字符串值)
{
viewRegisterPerform VRF=新的viewRegisterPerform();
VRF.MdiParent=此;
VRF.Show();
VRF.位置=新点(10,5);
}
在Vb.Net中:

<!-- language: vb.net -->
Private Sub UpdateListView(ByVal value As String)
    Dim VRF As ViewRegisterForm = New ViewRegisterForm()
    VRF.MdiParent = Me
    VRF.Show()
    VRF.Location = New Point(10, 5)
End Sub

私有子UpdateListView(ByVal值作为字符串)
作为ViewRegisterPerform的尺寸VRF=新的ViewRegisterPerform()
VRF.mdipent=Me
VRF.Show()
VRF.位置=新点(10,5)
端接头

这是winforms吗?如果您确定了正在使用的技术,这会有所帮助。如果代码中没有更新listview,您希望它如何工作?您可以在“ViewRegisterPerform”中创建一个属性来公开它的Listview,然后您可以通过访问该属性来修改Listview。因此,很抱歉。。。是的,我正在使用winformsIs ViewRegist执行窗体类的名称?您应该更新ViewRegisterPerform的一个实例,不要像更改静态属性那样尝试更改这些属性。第一行是命名空间驱动程序,第二行是公共部分类ViewRegisterPerform:Form{
<!-- language: vb.net -->
Private Sub UpdateListView(ByVal value As String)
    Dim VRF As ViewRegisterForm = New ViewRegisterForm()
    VRF.MdiParent = Me
    VRF.Show()
    VRF.Location = New Point(10, 5)
End Sub