• 0

[VB.NET] How to reference object from Panel


Question

I have too panels in my program, one of them has a list on it, and I want to reference the list from the other panel. To be more specific, my list is printersList in panel goPanel, and I want panel goPanel to reference it. I get the the error: "Reference to a non-shared member requires an object reference." I've done a lot of research on this error, for about the past hour, but have not been able to make sense out of it, can anyone point me in the right direction?

Thanks

25 answers to this question

Recommended Posts

  • 0

Not sure how I could show it in a screenshot, but basically:

- I have 2 user control forms, startPanel and goPanel

- I have a check list box (printersList) on startPanel, that I want to reference on goPanel, so I can list the things checked in the check box.

- When I try to do startPanel.printersList.CheckedItems, it says "Reference to a non-shared member requires an object reference."

  • 0

I think you have to loop through the controls in the panel, finding one of the right type (cast it as the type of control you're looking for) and then reference it that way.

That or provide a public accessor in the form that returns the control.

  • 0

Winston, it is a user control that is reference by a panel, so the short answer would be that it's a user control.

John, how would I go about doing that? That is what MSDN has said, but I can't get it working.

This is what MSDN says for the error I am getting:

  Quote
You have referenced a non-shared member within your code and failed to supply an object reference. You cannot use the class name itself to qualify a member that is not shared. The instance must first be declared as an object variable and then referenced by the variable name.

Error ID: BC30469

To correct this error

Declare the instance as an object variable.

Reference the instance by the variable name.

I'm not sure how to do this, can someone describe generally how I would set this up?

  • 0

you have to declare the list as public or friend, if u just dragged and dropped it on the form is going to be declared private and not accessible by by any other object than the one that instanciated it. Thats why you get a bad reference. John proposed an even better idea (and the correct OO way) of providing a public property or method to access the control while still keeping the control private.

  • 0

yea, that's what MSDN said to do (John's way), not sure how to go about that though. The checkedlistbox's name is printersList in user control startPanel, so when I try Dim printersList2 As CheckedListBox, and set printersList2 = startPanel.printersList, that doesn't work. Am I going about this wrong?

Edited by JK1150
  • 0

ok scratch what I said up there, new objects are declared as friends. If these are all panels on the same form you should be able to loop through. Can you give a more specific example of that you are trying to do? do you want to show the same list twice? or are you using the values from printerslist to modify another list on the form? also is this winform or webform? aslo can you post a screenie of what you are trying to do (just disable the reference line of code). Visuals help demonstrate your desired behavior

  • 0

i'm not sure what i could take a screenshot of, but I have a mainFrame (Windows App) with a panel in it. The program starts by loading a user control into the Panel, which includes printersList, a list of printers on a network that can be installed. The user will click start, which will change the panel to the user control goPanel with a progress bar, cancel button, etc., which will use what was checked on the checked list in startPanel to install the selected printers. This is a winform. Is there a specific part of this you want to see?

  • 0

It sounds to me like you need to have your user control expose the checked list box as a public property. That way other user controls have access to it.

In your code for your goPanel control, you'd have something like this (this is C#, hopefully you can translate it if you need to)

class MyGoPanelControl : UserControl

{

// Next line probably added by your designer automatically

private CheckedListBox printersList;

public CheckedListBox PrintersList

{

get { return printersList; }

}

}

then, anything that can access an instance of MyGoPanelControl, can access the printersList control inside of it via the property.

Is that what you were looking for?

  • 0

I would be very surprised if you could not returna checkedlistbox in visual basic .net. Its just a class like anything else. It just happens to also have a visual representation.

I ran my code through a converter to get it to VB.NET:

Class MyGoPanelControl

Inherits UserControl

' Next line probably added by your designer automatically

Private printersList As CheckedListBox

Public ReadOnly Property PrintersList() As CheckedListBox

Get

Return printersList

End Get

End Property

End Class

  • 0

Ok, i added a new user control, added a panel into the user control, dropped a checkedlistbox into the panel.

Now i added the new user control to my form, and added a button which adds new items to the checkedlistbox.

Check out the attachment to see if that's what you're after.

  • 0

If you put that button on another user control rather than in the main frame, that is basically what I need to know how to do.

(I have the users select printers from a list, click go, and then a progress screen will come up where the "goPanel" class will need to know which printers the user selected in the "startPanel" class)

Thanks for all your help so far, VB.NET certainly is an interesting learning experience.

Edited by JK1150
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Well, that's good to hear. No one here wants MAGAs to breed.
    • OpenAI announces significant updates to Codex and voice agent tools by Pradeep Viswanathan Apart from serving the ChatGPT experience to hundreds of millions of users everyday, OpenAI is also engaged in providing its platform for developers creating AI applications. OpenAI is popular among developers not just for its cutting-edge models, but also because of its strong tooling and support for developers. Today, OpenAI announced two significant updates for developers. The first is about Codex, OpenAI’s software engineering agent. OpenAI is now making Codex available to ChatGPT Plus users. For a limited time, ChatGPT Plus users will be able to enjoy generous usage limits, but OpenAI will rate-limit them during high-demand periods. Codex can now connect to the internet to install dependencies, upgrade packages, run tests that need external resources, and more. OpenAI specified that internet access is off by default, but users can enable it for specific environments. Users can also control the specific domains which Codex can access and more. This Codex Internet access capability is available for ChatGPT Plus, Pro, and Teams users, and it is coming soon to Enterprise users. With today’s update, Codex users can now update existing pull requests when following up on a task. Finally, users can now dictate tasks to Codex. Apart from the above and bug fixes, OpenAI has made the following improvements to Codex: Added support for binary files: When applying patches, all file operations are supported. When using PRs, only deleting or renaming binary files is supported for now. Improved error messages for setup scripts. Increased the limit on task diffs from 1 MB to 5 MB. Increased the limit for setup script duration from 5 to 10 minutes. Polished GitHub connection flow. Re-enabled Live Activities on iOS after resolving an issue with missed notifications. Removed the mandatory two-factor authentication requirement for users using SSO or social logins. The second major update from OpenAI today is about voice agents. OpenAI’s Agents SDK is now available in TypeScript and it comes with support for handoffs, guardrails, tracing, MCP, and other core agent primitives. This SDK also includes new support for human-in-the-loop approvals, allowing developers to pause tool execution, serialize and store the agent state, approve or reject specific calls, and resume the agent run. OpenAI also released an updated speech-to-speech model with improvements in instruction-following reliability, tool-calling consistency, and interruption behavior. Also, developers can now customize how fast the voice speaks during each session. Developers can now access the updated model via gpt-4o-realtime-preview-2025-06-03 in the Realtime API and gpt-4o-audio-preview-2025-06-03 in the Chat Completions API. Finally, the Traces dashboard now supports Realtime API sessions, allowing developers to easily visualize voice agent runs, including audio input/output, tool invocations, and interruptions.
    • VirtualBox 7.1.10 by Razvan Serea VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Targeted at server, desktop and embedded use, it is now the only professional-quality virtualization solution that is also Open Source Software. Presently, VirtualBox runs on Windows, Linux, macOS, and Solaris hosts and supports a large number of guest operating systems including but not limited to Windows (NT 4.0, 2000, XP, Server 2003, Vista, 7, 8, Windows 10 and Windows 11), DOS/Windows 3.x, Linux (2.4, 2.6, 3.x, 4.x, 5.x and 6.x), Solaris and OpenSolaris, OS/2, OpenBSD, NetBSD and FreeBSD. Some of the features of VirtualBox are: Modularity. VirtualBox has an extremely modular design with well-defined internal programming interfaces and a client/server design. This makes it easy to control it from several interfaces at once: for example, you can start a virtual machine in a typical virtual machine GUI and then control that machine from the command line, or possibly remotely. VirtualBox also comes with a full Software Development Kit: even though it is Open Source Software, you don't have to hack the source to write a new interface for VirtualBox. Virtual machine descriptions in XML. The configuration settings of virtual machines are stored entirely in XML and are independent of the local machines. Virtual machine definitions can therefore easily be ported to other computers. VirtualBox 7.1.10 changelog: VBoxManage: Fixed a crash when running 'guestcontrol run' on Windows hosts (bug #22175) Audio: Fixed device switching on Windows hosts (bug #22267) Windows host installer: Fixed multiple installation entries in the 'Add or remove programs' dialog and upgrade issues Linux host: Fixed issue which caused VM Selector process crash due to missing libdl.so and libpthread.so libraries (bug #22193) Linux host: Removed libIDL as a build time dependency when building VirtualBox from source code (bug #21169) Linux guest and host: Added initial support for kernel 6.15 (bug #22420) Linux guest: Added initial support for kernel 6.16-RC0 Linux guest and host: Fixed issue with building modules for UEK8 kernel on Oracle Linux 9 distribution RDP: Fixed issue when it was not possible to paste clipboard buffer into a guest over RDP remote session Download: VirtualBox 7.1.10 | 119.0 MB (Open Source) Download: VirtualBox 7.1.10 Extension Pack | 21.9 MB View: VirtualBox Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • I think the reason is, it is cross platform.
  • Recent Achievements

    • Week One Done
      jrromero17 earned a badge
      Week One Done
    • One Month Later
      jrromero17 earned a badge
      One Month Later
    • Conversation Starter
      johnwin1 earned a badge
      Conversation Starter
    • One Month Later
      Marwin earned a badge
      One Month Later
    • One Year In
      fred8615 earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      236
    2. 2
      snowy owl
      156
    3. 3
      ATLien_0
      139
    4. 4
      Xenon
      131
    5. 5
      +FloatingFatMan
      128
  • Tell a friend

    Love Neowin? Tell a friend!