-1

I got a hidden form (ViewRegisterForm) which has a ListView. This form is hidden, but I want to update the ListView from another form (RegistrationForm) during runtime.

To be honest I am not sure what is the best method to approach this scenario hence I am open to suggestions..

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

    }

Obviously this did not work!

8
  • Is this winforms? It would help if you identified the technologies in use.
    – user47589
    May 22, 2019 at 13:04
  • You are not updating the listview in the code, how would you expect it to work? You can create a property in ` ViewRegisterForm` to expose the Listview of it and then you can modify the listview by accessing the property
    – Chetan
    May 22, 2019 at 13:06
  • So sorry bout that... yes, I am working with winforms
    – Ronald
    May 22, 2019 at 13:06
  • Is ViewRegisterForm the name of the form's class? You should update an instance of a ViewRegisterForm not trying to change those properties like they were static
    – Steve
    May 22, 2019 at 13:06
  • first line is namespace Drivers and the second line is public partial class ViewRegisterForm : Form {
    – Ronald
    May 22, 2019 at 13:14

1 Answer 1

0

The issue you have is the following: You are trying to reference the class directly without making into an actual object.

Create the object first, and set it to the form type

ViewRegisterForm VRF = new ViewRegisterForm();

Now you will deal with this Object instead of the class itself.

Use VRF.PublicObjectInThisForm to call them

Here is the full example using your code.

In C#:

<!-- language: c# -->
 private void UpdateListView(string value)
    {
        ViewRegisterForm VRF = new ViewRegisterForm();
        VRF.MdiParent = this;   
        VRF.Show();
        VRF.Location = new Point(10, 5);
    }

In 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.