0

I am a hobby programmer in VB.Net. Have fairly good knowledge in that. However I got stuck in a place I need help.

  1. I have a main form called BTC_Main
  2. I have a different class called ClientID
  3. I would like to refer to the main form control in Client ID class file
  4. My Line in client ID "BTC_Main.Lvw_ClientID" gives an error "Reference to a non-shared member requires an object reference"

Could anyone help me?

Thanks in Advance.

  • 1
    Even though its C# this will explain how to do it https://stackoverflow.com/a/13537851/495455 – Jeremy Thompson Sep 18 '22 at 04:46
  • The control is ListView Control. I am using VS 2019. – Varadarajan R Sep 18 '22 at 04:50
  • 1
    Forms are just classes, and like any class you could have many instances. You need to tell it which instance of the class you want. – Joel Coehoorn Sep 18 '22 at 05:14
  • 1
    Use the `Application.OpenForms` collection. In particular look at `OfType()`. This will help you to get a reference to the form, assuming it is open. – Jonathan Willcock Sep 18 '22 at 05:43
  • The following may be helpful: https://stackoverflow.com/a/69743297/10024425 – Tu deschizi eu inchid Sep 18 '22 at 17:22
  • I added the line Public Shared BTC_Main As Object in the ClientID class and the error went off. – Varadarajan R Sep 18 '22 at 18:22
  • _and the error went off_. If that's the case, update your question with the actual code and details of what this error was and where encounter. – Hursey Sep 18 '22 at 20:27
  • The error did go off in that class. However a new problems are arising and I am working on them. Once completed, would be too happy share the solution. – Varadarajan R Sep 18 '22 at 22:54
  • Putting the line "Public Shared BTC_Main As Object" in more than one module generated problems and I could not access the form design at all. As I said I had removed the line "Public Shared BTC_Main As Object" in all the classes. I brought all references to main form control to main form class. Now no problem. – Varadarajan R Sep 21 '22 at 02:42

0 Answers0